[Include] SQLite Improved
#41

http://pastebin.com/z4KcbdJC
Reply
#42

having a similar problem to ReVo I think:

Код:
[10:25:27] [debug] Server crashed while executing attdef.amx
[10:25:27] [debug] AMX backtrace:
[10:25:27] [debug] #0 00005554 in bool:stmt_fetch_row (&DBStatement:stStatement=@0x001f1170) at C:\Users\Dracule\Dropbox\AADeathZone\pawno\include\sqlitei.inc:1724
[10:25:27] [debug] #1 0004a9e4 in public S@@_OnDialogResponse (playerid=0, dialogid=21, response=1, listitem=-1, inputtext[]=@0x001eddf8 "REMOVED PASSWORD") at C:\Users\Dracule\Dropbox\AADeathZone\gamemodes\attdef.pwn:2420
[10:25:27] [debug] Native backtrace:
[10:25:27] [debug] #0 f7dbf60b in _ZN10StackTraceC1EPv () from plugins/crashdetect.so
[10:25:27] [debug] #1 f7db6e92 in _ZN11CrashDetect20PrintNativeBacktraceEPv () from plugins/crashdetect.so
[10:25:27] [debug] #2 f7db88d9 in _ZN11CrashDetect11OnExceptionEPv () from plugins/crashdetect.so
[10:25:27] [debug] #3 f7dbf2a0 in ?? () from plugins/crashdetect.so
[10:25:27] [debug] #4 ffffe600 in ?? ()
[10:25:27] [debug] #5 f7dc1a27 in amx_Exec () from plugins/crashdetect.so
[10:25:27] [debug] #6 f7db8abb in _ZN11CrashDetect9DoAmxExecEPii () from plugins/crashdetect.so
[10:25:27] [debug] #7 f7dbb100 in ?? () from plugins/crashdetect.so
[10:25:27] [debug] #8 080ae33f in ?? () from /home/tcagame/MaiwandM/148/samp03svr
[10:25:27] [debug] #9 080b97da in ?? () from /home/tcagame/MaiwandM/148/samp03svr
[10:25:27] [debug] #10 08071ae8 in ?? () from /home/tcagame/MaiwandM/148/samp03svr
[10:25:27] [debug] #11 08071be2 in ?? () from /home/tcagame/MaiwandM/148/samp03svr
[10:25:27] [debug] #12 0807ba00 in ?? () from /home/tcagame/MaiwandM/148/samp03svr
[10:25:27] [debug] #13 080b59ad in ?? () from /home/tcagame/MaiwandM/148/samp03svr
[10:25:27] [debug] #14 080b5b42 in ?? () from /home/tcagame/MaiwandM/148/samp03svr
[10:25:27] [debug] #15 080b1453 in ?? () from /home/tcagame/MaiwandM/148/samp03svr
[10:25:27] [debug] #16 00272ebc in __libc_start_main () from /lib/libc.so.6
[10:25:27] [debug] #17 0804b521 in ?? () from /home/tcagame/MaiwandM/148/samp03svr
after it restarted, it wouldn't even properly open the database:
Код:
[10:25:29] SQLitei Error: (db_query) Invalid persistent database given (F71EB748).
[10:25:29] SQLitei Notice: (db_free_result_hook) Invalid result given.
[10:25:29] Server Config Loaded.
[10:25:29] SQLitei Error: (db_query) Invalid persistent database given (F71EB748).
[10:25:29] SQLitei Notice: (db_free_result_hook) Invalid result given.
[10:25:29] Bases Loaded: 0
[10:25:29] SQLitei Error: (db_query) Invalid persistent database given (F71EB748).
[10:25:29] Arenas Loaded: 0
[10:25:29] SQLitei Error: (db_query) Invalid persistent database given (F71EB748).
[10:25:29] DMs Loaded: 0
[10:25:29] SQLitei Error: (db_query) Invalid persistent database given (F71EB748).
[10:25:29] Duels Loaded: 0
[10:25:29] SQLitei Error: (db_query) Invalid persistent database given (F71EB748).
[10:25:29] SQLitei Notice: (db_free_result_hook) Invalid result given.
[10:25:29] Bases Loaded: 0
the code:


pawn Код:
new Query[256];
            format(Query, sizeof(Query), "SELECT * FROM `Players` WHERE `Name` = '%s' AND `Password` = '%s'", Player[playerid][Name], HashPass);
            new DBStatement:stmt = db_prepare(sqliteconnection, Query);
            new level, weather, time, chatchannel, netcheck;
            stmt_bind_result_field(stmt, 1, DB::TYPE_STRING, CurrentPassword, sizeof(CurrentPassword));
            stmt_bind_result_field(stmt, 2, DB::TYPE_INT, level);
            stmt_bind_result_field(stmt, 3, DB::TYPE_INT, weather);
            stmt_bind_result_field(stmt, 4, DB::TYPE_INT, time);
            stmt_bind_result_field(stmt, 5, DB::TYPE_INT, chatchannel);
            stmt_bind_result_field(stmt, 6, DB::TYPE_INT, netcheck);
           
   
            if(stmt_execute(stmt)) {
                if(stmt_fetch_row(stmt)) {
                    Player[playerid][Level] = level;
                    Player[playerid][Weather] = weather;
                    Player[playerid][Time] = time;
                    Player[playerid][ChatChannel] = chatchannel;
                    Player[playerid][NetCheck] = netcheck;
                   
                    Player[playerid][Logged] = true;

                    SendClientMessage(playerid,-1, "You have successfully logged in.");
                    format(Query, sizeof(Query), "Level: %d | Weather: %d | Time: %d | Chat Channel: %d | Net Check: %d", level, weather, time, chatchannel, netcheck);
                    SendClientMessage(playerid, -1, Query);
                   
           
                } else {
                    SendClientMessage(playerid,-1,"{FFFFFF}Error: {0099FF}Wrong Password. Please try again.");
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"{FFFFFF}Login Dialog","{FFFFFF}Type your password below to log in:","Login","Leave");
                }
            }
           
            stmt_close(stmt);
for now, I just won't use prepared statements.

Works on windows, doesn't work on Linux, www.hostspree.org
Reply
#43

Did you use db_open_persistent or just db_open?

I suspect there's a bug when using db_open, which can be worked around by using db_open_persistent.
Reply
#44

Hmmm nice improvement
Reply
#45

What's better? This or BUD?
Reply
#46

Quote:
Originally Posted by rhds
Посмотреть сообщение
What's better? This or BUD?
They're separate things. SQLite Improved is not a user system. You can use both, in fact.
Reply
#47

Awesome slice great
Reply
#48

Anyone have tested it using Linux?
Last time i used Linux this include wasn't compatible (cause crash, see my post above).
Reply
#49

Worked fine when I tested it. Which Linux dist?
Reply
#50

Time ago i was with centos (i dont remember if was 5 or 6, but 6 maybe.)
Reply
#51

pawn Код:
stock Float:db_get_field_float(DBResult:dbrResult, iField = 0) {
    if (dbrResult == DB::INVALID_RESULT) {
        DB::Notice("(db_get_field_float) Invalid result given.");
       
        return 0.0;
    }

    if (!db_num_rows(dbrResult)) {
        DB::Notice("(db_get_field_int) Empty result given.");

        return 0.0;
    }

    if (iField < 0 || db_num_fields(dbrResult) <= iField) {
        DB::Notice("(db_get_field_int) Given field index doesn't exist in the result.");

        return 0.0;
    }
   
    db_get_field(dbrResult, iField, gs_szBuffer, sizeof(gs_szBuffer) - 1);
   
    return floatstr(gs_szBuffer);
}
You forgot to return floats here, so I just edited it for you
Reply
#52

Update!
I finally managed to get error messages from db_query!

pawn Код:
new DB:db = db_open("test.db");

// no such table: some_table
db_query(db, "SELECT * FROM some_table;");
// No error (or "table test already exists" if you run it again)
db_query(db, "CREATE TABLE test (a, b, c)");
// no such column name: name
db_query(db, "SELECT name FROM test");
// near "bla": syntax error
db_query(db, "SELECT test FRMO bla");

db_close(db);
To use this, you must download amx_assembly (.zip) and put it with your include files.
After that, define DB_QUERY_ERRORS like this:
pawn Код:
#define DB_QUERY_ERRORS true
// automatically print errors (it's true by default)
#define DB_PRINT_ERRORS true
#include <sqlitei>
It might seem like a simple thing, but here's what I had to do to get it working: https://github.com/oscar-broman/sqli...b7fa2d8658b3b1
Reply
#53

Excellent include, especially love the prepared statements feature.
Reply
#54

good job
Reply
#55

So as I understand I don't need to use SQL injection anymore. Correct me if I'm wrong.

Do you have any example of updating data?
Reply
#56

Could you add the question marks to db_exec?

Also want to say: Great work Saved me lot of code I was using previously.
Reply
#57

Hi there. I'm working on someone's script, and I used sqlitei to get better debug info for now. Well, I started and got something like
Quote:

[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!
[16:04:58] SQLitei Warning: (db_autofree_result) The autofree pool is full!

Is that because the original writer never freed stuff? No idea yet where from it's coming, but what should I look for?
Reply
#58

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Hi there. I'm working on someone's script, and I used sqlitei to get better debug info for now. Well, I started and got something like

Is that because the original writer never freed stuff? No idea yet where from it's coming, but what should I look for?
It's because of memory leaks, yes. You could modify the size of gs_adbrAutoFreeResults until the errors stop (that's a good start if you need it fixed quickly).

Look for queries executed inside loops.

The easiest way, however, is if you have crashdetect.inc. You could modify sqlitei.inc to print a backtrace here.
Reply
#59

I just enabled DB_DEBUG, and yeah, awesome code firing 2k+ queries in a row without freeing them. I wanted to use DB_QUERY_ERRORS, but amx_assembly crashes on my PC (I disabled DEP, but still crash on SysreqD). Still, I'm really grateful for this library, I'll use it always when dealing with sqlite! Thank you
Reply
#60

DB_QUERY_ERRORS should work without crashdetect - I think I need to use SysreqC instead.
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)