How to use SQLite3?
#3
(05-08-2015, 05:15 PM)xoft Wrote: You'll need at least a basic crash-course in general database design and SQL language, those are available all over the Net. Once you have an idea of how to structure your data tables, and how to query them for information and how to insert information into them, you'll be able to work with the API rather naturally. You basically use just 3 functions from the sqlite API - open(), close() and exec(). Open and close are easy - they just open and close the database files. Exec is where all the important stuff happens - it executes ANY sql code.
Of course, in time you'll want to upgrade to using prepared statements. These are what most plugins nowadays use. Basically with statements you say "I want to execute this sql code several times, each time the same statement but with different data. And give me results one at a time".

I'd recommend having a look at the Gallery plugin's Storage_SQLite file, it implements the entire SQLite storage mechanism for the Gallery plugin:
https://github.com/mc-server/Gallery/blo...SQLite.lua
A good example of working with the database is the RemoveArea() function: https://github.com/mc-server/Gallery/blo...#L835-L871
It inserts data to one table and removes data from two other tables.
The LoadAllPlayerAreas() function, on the other hand, queries the database for data in a basic way: https://github.com/mc-server/Gallery/blo...#L835-L871

Alright, i'll give things a try.
Reply
Thanks given by:


Messages In This Thread
How to use SQLite3? - by Shadowraix - 05-08-2015, 12:28 PM
RE: How to use SQLite3? - by xoft - 05-08-2015, 05:15 PM
RE: How to use SQLite3? - by Shadowraix - 05-10-2015, 12:21 AM
RE: How to use SQLite3? - by Shadowraix - 05-10-2015, 10:39 AM
RE: How to use SQLite3? - by xoft - 05-10-2015, 03:59 PM
RE: How to use SQLite3? - by Shadowraix - 05-10-2015, 04:13 PM
RE: How to use SQLite3? - by LogicParrot - 05-10-2015, 11:42 PM
RE: How to use SQLite3? - by NathanFlurry - 05-11-2015, 04:27 AM
RE: How to use SQLite3? - by xoft - 05-11-2015, 07:31 AM
RE: How to use SQLite3? - by Aggroblut - 06-02-2015, 01:43 AM
RE: How to use SQLite3? - by xoft - 06-02-2015, 02:07 AM



Users browsing this thread: 2 Guest(s)