Jump to content

SQLite problems


rockleg

Recommended Posts

Posted

im having a problem with SQLite, i'm connecting to the database but the table is not created

local db = dbConnect('sqlite', 'accounts.db') 
dbQuery(db, 'CREATE TABLE IF NOT EXISTS accounts') 

Posted

You haven't specified any columns for the table. The basic syntax is this:

CREATE TABLE IF NOT EXISTS accounts (column1 TEXT, column2 INTEGER) 

Also, don't use dbQuery when you don't need to return anything.

Posted

Yes. Use /debugscript 3 to check for any errors/warnings in your scripts.

You can also use /debugdb 2 to set the logging level which could help you identify database problems in the future.

Posted

dbExec returns a boolean value, mostly true unless the connection is incorrect.

dbQuery returns a query handle which can be polled using dbPoll to get the returned data. It's mostly used with SELECT.

Posted

You can check the wiki page of any function for the syntax and a basic example.

local qh = dbQuery('SELECT * FROM accounts') 
local results = dbPoll(qh, -1) 

-1 means that it will wait for the database to return the results. You can also use callbacks which is better because it doesn't freeze the server till the data is returned.

Posted

am i using callbacks right?

local qh = dbQuery(callback, db, 'SELECT * FROM accounts') 
  
function callback(qh) 
 local results = dbPoll(qh, -1) 
end 

Posted

You don't need to store the query handle returned from dbQuery since you're using callbacks. You don't need to use -1 as the timeout since the data will surely be ready, you can just use 0.

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...