SQLite question. -
Outbreak - 25.11.2009
I've just started learning and trying out SQLite.
I've seen a few, but not many examples on SAMP forums of how to use it and certain functions.
I've created this as a test. The only thing i really have to open it is notepad
The reason i want to open it is to check to see whats actually gone inside, and see if its working..
So here is the code...
http://pastebin.com/m38c8192b
Indention went a little bit tits up when i pasted it in pastebin, but it isnt too bad.
Here is the result i find when i start the server, and the users.s3db file has been created.
http://pastebin.com/m4b6f1fdd
Remeber, it was opened in notepad, so that is pasted from notepad.
Then here is what its like after i connect...
http://pastebin.com/m736b591e
So, questions are.
What is that about? It obviously hasn't worked right because tyhe information i was wanting to insert into there hasnt worked when i connected.
Are there any programs i can use to view the database fully, as a database should look. Rather than using notepad?
What did i do wrong in that code?
I saw some examples, and mine seemed to comply with those.
Re: SQLite question. -
Outbreak - 26.11.2009
It's almost 12 hours, so im bumpin.
Anyone able to answer my first post?
Thanks.
Re: SQLite question. - Zeex - 26.11.2009
So... if I understand correctly... you're editing db files with text editor?!
OK, look at
this page then, there is a big list of SQLite management tools.
I recommend you
this one, it is simple and powerful.
Re: SQLite question. -
Outbreak - 26.11.2009
No i was using pawno, and i wanted to check the output to see if it worked. The only thing i had was notepad to view the database file.
I'm just not sure why it didnt input the correct information, and i'd like sometihng i can view the database in full with an actual database layout.
EDIT: By the way, thanks for the links. I like the sqlite admin software, i can view the database exactly how i wanted to.
Now im just unsure why the info was blank and the script didnt insert the info intothe database as i wanted.
Re: SQLite question. -
Dabombber - 26.11.2009
You should probability make `name` the primary key or at least make it unique, otherwise you will end up with multiple entries with the same name. You should also use UPDATE when possible (if `name` is unique/the primary key, then insert will fail if the name is already in the database), doing a select first is the only way to tell if you need to insert or update.
[code=sql]CREATE TABLE IF NOT EXISTS 'Users' ( 'name' TEXT NOT NULL DEFAULT '' , `skin` INTEGER NOT NULL DEFAULT 0 , `IP` TEXT NOT NULL DEFAULT '0.0.0.0' );[/code]
Users is a table not a string, so it should be `Users`, same with name being a column (`name` instead of 'name'), sqlite doesn't really care but it's not good practise. Also you don't need the ;.
[code=sql]INSERT INTO `Users` ( 'skin' ) VALUES ( %d )[/code]
This isn't associating the skin (`skin` btw) with any name so its just inserting a column with `name` = '', `IP` = '0.0.0.0', and `skin` = 0 (there's only one class).
[code=sql]INSERT INTO `Users` ( `name` , `IP` ) VALUES ( '%s' , %s )[/code]
The IP is a string so it needs to be '%s'.
Re: SQLite question. -
Outbreak - 26.11.2009
Thanks, its actually worked
When i open it in SQLite Admin i check the table and the results i get
name | skin | IP |
[sLK]Outbreak 0 127.0.0.1
Which is exactly how its mean to be. Since im using my own computer to test it, thats why im getting that IP address.
So now i'll create another few fields, for kills, deaths and money. Then i'll check to see if i can retrieve the information when i connect again.