Cuberite Forum
[SOLVED] Sqlite3 Rows - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: [SOLVED] Sqlite3 Rows (/thread-2574.html)

Pages: 1 2


[SOLVED] Sqlite3 Rows - denwo - 11-03-2016

I'm making a plugin and need to store some data.

I'm using sqlite3 and everytime i run my cuberite server i see this error.

[10:45:24] Can't load plugin TestPlugin because of an initialization error in file Plugins/TestPlugin/test.lua: 2 (no such table: table)

Here's my code

db = sqlite3.open('test.sqlite3')
LOG(db.rows('SELECT * FROM table'))
db:close()


EDIT:
i just realised that i'm an idiot the db files were located in cuberite's folder not in the plugin's folder


RE: Sqlite3 Rows. - NiLSPACE - 11-03-2016

Just like any SQL engine you have to create the tables first: https://github.com/cuberite/WorldEdit/blob/master/Storage/ChangeScripts/1.sql


RE: Sqlite3 Rows. - denwo - 11-03-2016

(11-03-2016, 01:56 AM)NiLSPACE Wrote: Just like any SQL engine you have to create the tables first: https://github.com/cuberite/WorldEdit/blob/master/Storage/ChangeScripts/1.sql
i undestand how sql works i have already created the table and add a couple of rows.


RE: Sqlite3 Rows. - NiLSPACE - 11-03-2016

You can take a look at the Gallery plugin. It has an ExecuteStatement method which you give the SQL statement, optional parameters and optional callback: https://github.com/cuberite/gallery/blob/master/Storage_SQLite.lua#L83-L108
Then you can use it like this: https://github.com/cuberite/gallery/blob/master/Storage_SQLite.lua#L237-L249


RE: Sqlite3 Rows. - xoft - 11-03-2016

First, you should be calling methods on the "db" object with a colon: db:rows(...)
Second, db:rows(...) creates an iterator, the LOG function cannot output the value of an iterator.


RE: Sqlite3 Rows. - xoft - 11-03-2016

If you want to output the values in all rows, you can do this:
for a in db:rows('SELECT * FROM table') do
  for k, v in pairs(a) do
    LOG(k .. " = " .. v)
  end
end



RE: Sqlite3 Rows. - denwo - 11-03-2016

[09:32:47] Can't load plugin TestPlugin because of an initialization error in file Plugins/TestPlugin/test.lua: 2 (no such table: test)
@xoft ft tried it didn't work


RE: Sqlite3 Rows. - xoft - 11-04-2016

Then you'll have to post your entire code for the Initialize function and the database you're using.


RE: Sqlite3 Rows. - denwo - 11-04-2016

i've sent you a pm


RE: Sqlite3 Rows. - denwo - 11-05-2016

I've tried to change the name (in-order to make a new sqlite3 file) it failed.

Any ideas?