Jump to content

Sql problem


Recommended Posts

Hi guys - i have problem with my database. I made some db in "sqlite browser" and i made table named "characters" and then i put some records. Here is lua code:

addEventHandler("onResourceStart", resourceRoot,  
function() 
    database = dbConnect("sqlite", "projectsa.db") 
    local query = dbQuery( database, "SELECT * FROM characters") 
    outputChatBox(tostring(query)) 
    local result, rows, msg = dbPoll(query, 0) 
    if result == false then 
        outputConsole( "dbPoll failed. Error code: " .. tostring(rows) .. "  Error message: " .. tostring(msg) ) 
    end 
end) 

,

but when im starting script im getting:

dbPoll failed. Error code: 1  Error message: no such table "characters" 

What's wrong?

I'm sure that table is in there, and im get connection from "dbConnect" function and query from "dbQuery".

Link to comment

That's because you never created that table, use this:

addEventHandler("onResourceStart", resourceRoot, 
function() 
    database = dbConnect("sqlite", "projectsa.db") 
    local exec = dbExec(database, "CREATE TABLE IF NOT EXISTS 'characters' ( characterID TEXT PRIMARY KEY )" ) 
    local query = dbQuery( database, "SELECT * FROM characters") 
    outputChatBox(tostring(query)) 
    local result, rows, msg = dbPoll(query, 0) 
    if result == false then 
        outputConsole( "dbPoll failed. Error code: " .. tostring(rows) .. "  Error message: " .. tostring(msg) ) 
    end 
end) 

Which is this:

    local exec = dbExec(database, "CREATE TABLE IF NOT EXISTS 'characters' ( characterID TEXT PRIMARY KEY )" ) 
  

Link to comment

I fixed that .. i thought that .db file is in main folder, but yes it was but i was in "database" folder too so i thought that this in main is my database which im connecting so i all the time open this one. Now i know it was wrong .. thanks for help.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...