rockleg Posted September 9, 2015 Share Posted September 9, 2015 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') Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 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. Link to comment
rockleg Posted September 9, 2015 Author Share Posted September 9, 2015 like this? dbExec(db, 'CREATE TABLE IF NOT EXISTS accounts (account TEXT)') Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 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. Link to comment
rockleg Posted September 9, 2015 Author Share Posted September 9, 2015 whats the difference between dbQuery and dbExec? Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 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. Link to comment
rockleg Posted September 9, 2015 Author Share Posted September 9, 2015 are there any SQLite tutorials that i should read? Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 I made one some time ago: viewtopic.php?f=148&t=38203 Link to comment
rockleg Posted September 9, 2015 Author Share Posted September 9, 2015 how can i use dbPoll Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 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. Link to comment
rockleg Posted September 9, 2015 Author Share Posted September 9, 2015 am i using callbacks right? local qh = dbQuery(callback, db, 'SELECT * FROM accounts') function callback(qh) local results = dbPoll(qh, -1) end Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 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. Link to comment
rockleg Posted September 9, 2015 Author Share Posted September 9, 2015 is there a way to return the results without callbacks and without freezing the server? Link to comment
JR10 Posted September 9, 2015 Share Posted September 9, 2015 You mean from a function? One way to do that would be coroutines. viewtopic.php?f=91&t=86184&p=779671&hilit=coroutine#p779671 viewtopic.php?f=91&t=92076&p=828272&hilit=coroutine#p828272 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now