Piorun Posted May 3, 2013 Share Posted May 3, 2013 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
Metall Posted May 3, 2013 Share Posted May 3, 2013 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
Piorun Posted May 3, 2013 Author Share Posted May 3, 2013 e ok but why "characterID" is "TEXT" type? Link to comment
Metall Posted May 3, 2013 Share Posted May 3, 2013 e ok but why "characterID" is "TEXT" type? I guess it's because TEXT means that it's a text, like the name of a vehicle or so. So i think that'll work anyways. Link to comment
Piorun Posted May 3, 2013 Author Share Posted May 3, 2013 Another question - what is good program to open .db files? Link to comment
Piorun Posted May 3, 2013 Author Share Posted May 3, 2013 Ye but when im opeining database with tables made by dbExec i dont see any in database structure. I have 2.0 b1 ver. Link to comment
iPrestege Posted May 3, 2013 Share Posted May 3, 2013 Try this one ; http://sourceforge.net/projects/sqlitebrowser/ Link to comment
Piorun Posted May 3, 2013 Author Share Posted May 3, 2013 Anyway - if i made some table in "database browser" i cant manage this table using db... functions. Link to comment
Piorun Posted May 3, 2013 Author Share Posted May 3, 2013 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
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