SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 19/03/2017, 09:02 AM   #1
RyderX
Banned
 
Join Date: Oct 2016
Location: Lebanon,Beirut Rank: SA-MP Scripter
Posts: 564
Reputation: 53
Default SQLite question

Hello there! so i have started learning SQLite ways, but i got a little question about it,

For example i tried this first to test,

PHP Code:
#include <a_samp>
#include <a_sampdb>
#include <zcmd>

main() { }

new 
DBsomeDB// Handle for database. Our queries need to use this so the queries know where to handle things

public OnGameModeInit() {
   
someDB db_open("your.db"); // file 'your.db' will be our SQLite database
}
CMD:getmyname(playeridparams[]) {
    new 
szQuery[74], szOut[32], DBResultqueryszPlayerName[MAX_PLAYER_NAME];

    
GetPlayerName(playeridszPlayerNameMAX_PLAYER_NAME);
    
format(szQuerysizeof(szQuery), "select * from `players` where `playername` = '%s'"szPlayerName);
    
query db_query(someDBszQuery);
    if(
db_num_rows(query) > 0) {
        
SendClientMessage(playerid0"There is more than 0 rows, meaning there is at least 1 row!");
        
SendClientMessage(playerid0"So there is a registered account with my name!");
        
db_get_field_assoc(query"Motto"szOutsizeof(szOut));
        
SendClientMessage(playerid0"Your motto is:");
        
SendClientMessage(playerid0szOut);
        
db_free_result(query);
    }

    return 
1;

it's from a tutorial, i would know how to make a database in scriptfiles, for example like yourdb.dll, it got compiled gratefully but didn't show any file in scriptfiles, does it require player to join the server and use it and to be showen? thanks anyway!
RyderX is offline   Reply With Quote
Old 19/03/2017, 09:05 AM   #2
iKarim
Banned
 
Join Date: Oct 2015
Posts: 581
Reputation: 142
Default Re: SQLite question

db_open native will automatically create the database if doesn't exist.
iKarim is offline   Reply With Quote
Old 19/03/2017, 09:08 AM   #3
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,863
Reputation: 1399
Default Re: SQLite question

As soon as the server will start, it will create the file which will be empty. Make sure scriptfiles have correct permissions.

Two more things: %q in format to escape strings and free the result at the very end (because it doesn't free the result if there are not any rows).
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 19/03/2017, 09:10 AM   #4
RyderX
Banned
 
Join Date: Oct 2016
Location: Lebanon,Beirut Rank: SA-MP Scripter
Posts: 564
Reputation: 53
Default Re: SQLite question

Quote:
Originally Posted by Konstantinos View Post
As soon as the server will start, it will create the file which will be empty. Make sure scriptfiles have correct permissions.

Two more things: %q in format to escape strings and free the result at the very end (because it doesn't free the result if there are not any rows).
Yea i have noticed that, thanks btw

Quote:
Originally Posted by PawnHunter View Post
db_open native will automatically create the database if doesn't exist.
Okay Thanks.
RyderX is offline   Reply With Quote
Old 19/03/2017, 09:17 AM   #5
Logic_
Banned
 
Join Date: Jun 2015
Posts: 1,514
Reputation: 305
Default Re: SQLite question

Good to see you doing something finally (sarcastic facepalm :P)

I'd recommend you to read Sreyas' SQL introduction and some other good tutorials to know some basics. Best of luck in learning.
Logic_ is offline   Reply With Quote
Old 19/03/2017, 09:18 AM   #6
Hunud
Gangsta
 
Hunud's Avatar
 
Join Date: Jun 2016
Location: Right here.
Posts: 602
Reputation: 53
Default Re: SQLite question

He is.not.even responsible to do yini but this.... Nice try
Hunud is offline   Reply With Quote
Old 19/03/2017, 09:33 AM   #7
RyderX
Banned
 
Join Date: Oct 2016
Location: Lebanon,Beirut Rank: SA-MP Scripter
Posts: 564
Reputation: 53
Default Re: SQLite question

Quote:
Originally Posted by Hunud View Post
He is.not.even responsible to do yini but this.... Nice try
Thanks pro.

Quote:
Originally Posted by Logic_ View Post
Good to see you doing something finally (sarcastic facepalm :P)

I'd recommend you to read Sreyas' SQL introduction and some other good tutorials to know some basics. Best of luck in learning.
Ok thank you.
RyderX is offline   Reply With Quote
Old 19/03/2017, 11:25 AM   #8
Eoussama
High-roller
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,072
Reputation: 267
Default Re: SQLite question

Nice decision moving to SQL, best of luck mate
__________________

|===[Web taxi]===|
List of my work
Github
Pastebin

|===[Interesting topics]===|
Semantic Versioning
Eoussama is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sqlite question Thoma Scripting Help 2 13/09/2015 10:53 AM
SQLite question DarkLored Scripting Help 1 05/08/2015 07:29 PM
SQLite question LocMax Scripting Help 5 03/06/2014 04:39 AM
SQLite Question iTzZh Scripting Help 2 25/11/2012 07:51 AM
SQLite Question Norn Help Archive 5 10/09/2010 05:29 PM


All times are GMT. The time now is 10:59 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.