[Include] Easy MySQL - Simplifying the usage of MySQL queries!
#41

Quote:
Originally Posted by Private200
Посмотреть сообщение
Even if old, I believe my MySQL include is easier to be understood and used: https://sampforum.blast.hk/showthread.php?tid=609990
Go to ur post this include easier all of them.
Reply
#42

Quote:
Originally Posted by Max_Andolini
Посмотреть сообщение
Go to ur post this include easier all of them.
You still got that toxic attitude after years. I am not advertising nor trying to get people to my include; I had totally forgotten I had released it. Try to appreciate other's work if you want yours to get appreciated.. what a mentality.
Reply
#43

Quote:
Originally Posted by Private200
Посмотреть сообщение
Even if old, I believe my MySQL include is easier to be understood and used: https://sampforum.blast.hk/showthread.php?tid=609990
No offense, but your include is a bit far from being better and easier than that.
Reply
#44

Hey max, rep+ for this i love it but i was wonder if you can go to the other level and make a tutorial about using some of the functions that aren't the basic. The samp community would greatly appreciate.
Reply
#45

Quote:
Originally Posted by Akeem
Посмотреть сообщение
Hey max, rep+ for this i love it but i was wonder if you can go to the other level and make a tutorial about using some of the functions that aren't the basic. The samp community would greatly appreciate.
Thank you. Look here for tutorial. https://github.com/ThreeKingz/easy-m...ster/README.md
Reply
#46

Wow, gonna port my account saving to mysql, +REP for you!
Reply
#47

Update published.

-Added more logtype.
-Small changes.
-Added every query error print.

https://github.com/ThreeKingz/easy-m...easy-mysql.inc
Reply
#48

Quote:
Originally Posted by JR_Junior
Посмотреть сообщение
The following code is not working:
PHP код:
    new string[128], names[24],money;
    new 
handle = SQL::OpenEx(SQL::MREAD, "Accounts", "", -1, 10, -1, "Money");
    
SQL::ReadRetrievedRows(handle, i)
    {
        
SQL::ReadString(handle, "AccountName", names, 24, i);
        
SQL::ReadInt(handle, "Money", money, i);
        
format(string, sizeof(string), "Name %s | Money: %d", names,money);
        
SendClientMessage(playerid, -1, string);
    }
    
SQL::Close(handle); 
Accounts in DB: 7

In the Mysql log:
PHP код:
[13:42:36] [DEBUG] mysql_query(1, "SELECT * FROM `Accounts` WHERE `Money`='' ORDER BY `Money` DESC LIMIT 10 ", 1)
[
13:42:36] [DEBUG] CHandle::Execute(this=0x4f8c170, type=3, query=0x6705fd0)
[
13:42:36] [DEBUG] CConnection::Execute(query=0x6705fd0, this=0x674f80, connection=0x4fa5968)
[
13:42:36] [DEBUG] CQuery::Execute(this=0x6705fd0, connection=0x4fa5968)
[
13:42:36] [INFO] query "SELECT * FROM `Accounts` WHERE `Money`='' ORDER BY `Money` DESC LIMIT 10 " successfully executed within 0.616 milliseconds
[13:42:36] [DEBUG] CResultSet::Create(connection=0x4fa5968, query_str='SELECT * FROM `Accounts` WHERE `Money`='' ORDER BY `Money` DESC LIMIT 10 ')
[
13:42:36] [DEBUG] created new resultset '0x6710788'
[13:42:36] [DEBUG] fetched MySQL result '0x66f8990'
[13:42:36] [DEBUG] allocated 0 bytes for PAWN result
[13:42:36] [DEBUG] CHandle::Execute - return value: true
[13:42:36] [DEBUG] mysql_query: return value: '1'
[13:42:36] [DEBUG] cache_is_valid(1)
[
13:42:36] [DEBUG] cache_is_valid: return value: 'true'
[13:42:36] [DEBUG] cache_get_row_count(0x05FFF1E0)
[
13:42:36] [DEBUG] cache_get_row_count: return value: '1'
[13:42:36] [DEBUG] cache_get_row_count(0x05FFF1D8)
[
13:42:36] [DEBUG] cache_get_row_count: return value: '1'
[13:42:36] [DEBUG] cache_is_valid(1)
[
13:42:36] [DEBUG] cache_is_valid: return value: 'true'
[13:42:36] [DEBUG] cache_delete(1)
[
13:42:36] [DEBUG] cache_delete: return value: '1' 
Tried too: new handle = SQL::Open(SQL::MREAD, "Accounts", "Money", -1, "", -1, "", -1, -1, "Money");

But no data in chat!
Update include and try this.

https://github.com/ThreeKingz/easy-m...easy-mysql.inc

PHP код:
    new string[128], names[24],money;
    new 
handle = SQL::OpenEx(SQL::MREAD, "Accounts", "", -1, 10, -1, "Money");
    
SQL::ReadRetrievedRows(handle, i)
    {
        
SQL::ReadString(handle, "AccountName", names, 24, i);
        
SQL::ReadInt(handle, "Money", money, i);
        
format(string, sizeof(string), "Name %s | Money: %d", names,money);
        
SendClientMessage(playerid, -1, string);
    }
    
SQL::Close(handle); 
Reply
#49

Quote:
Originally Posted by Max_Andolini
Посмотреть сообщение
Update include and try this.

https://github.com/ThreeKingz/easy-m...easy-mysql.inc

PHP код:
    new string[128], names[24],money;
    new 
handle = SQL::OpenEx(SQL::MREAD, "Accounts", "", -1, 10, -1, "Money");
    
SQL::ReadRetrievedRows(handle, i)
    {
        
SQL::ReadString(handle, "AccountName", names, 24, i);
        
SQL::ReadInt(handle, "Money", money, i);
        
format(string, sizeof(string), "Name %s | Money: %d", names,money);
        
SendClientMessage(playerid, -1, string);
    }
    
SQL::Close(handle); 
Thanks for this update!

But I get this error:
PHP код:
...\pawno\include\easy-mysql.inc(191) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(254) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(307) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(370) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(402) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(463) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(516) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(553) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(606) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(638) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(2097) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(2393) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(2407) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(2462) : warning 213: tag mismatch 
PHP код:
if(mysql_errno(SQL::ReadCache[i]) != 0) 
Reply
#50

Quote:
Originally Posted by JR_Junior
Посмотреть сообщение
Thanks for this update!

But I get this error:
PHP код:
...\pawno\include\easy-mysql.inc(191) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(254) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(307) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(370) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(402) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(463) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(516) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(553) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(606) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(638) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(2097) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(2393) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(2407) : warning 213: tag mismatch
...\pawno\include\easy-mysql.inc(2462) : warning 213: tag mismatch 
PHP код:
if(mysql_errno(SQL::ReadCache[i]) != 0) 
Update again.
Reply
#51

Quote:
Originally Posted by Max_Andolini
Посмотреть сообщение
Update again.
Now:
PHP код:
...\gamemodes\GM.pwn(2046) : error 035: argument type mismatch (argument 4) 
PHP код:
new handle = SQL::OpenEx(SQL::MREAD, "Accounts", "", -1, 10, -1, "Money"); 
Reply
#52

Thank you very much for this update!
It's working perfectly now.

Keep improving this wonderful include.
Reply
#53

PHP код:
SQL::DeleteRowEx2
SQL
::GetStringEntryEx2
SQL
::t_GetStringEntryEx2
SQL
::GetIntEntryEx2
SQL
::GetFloatEntryEx2
SQL
::SetIntEntryEx2
SQL
::SetStringEntry2
SQL
::SetStringEntryEx2
SQL
::SetFloatEntryEx2
SQL
::RowExistsEx2
SQL
::DeleteRow3 
All these functions use the "%e" specifier using the normal format instead of mysql_format, so they won't work. I noticed this when I tried using RowExistsEx2.
Reply
#54

Quote:
Originally Posted by CantBeJohn
Посмотреть сообщение
PHP код:
SQL::DeleteRowEx2
SQL
::GetStringEntryEx2
SQL
::t_GetStringEntryEx2
SQL
::GetIntEntryEx2
SQL
::GetFloatEntryEx2
SQL
::SetIntEntryEx2
SQL
::SetStringEntry2
SQL
::SetStringEntryEx2
SQL
::SetFloatEntryEx2
SQL
::RowExistsEx2
SQL
::DeleteRow3 
All these functions use the "%e" specifier using the normal format instead of mysql_format, so they won't work. I noticed this when I tried using RowExistsEx2.
Send me your code.
Reply
#55

Quote:
Originally Posted by Max_Andolini
Посмотреть сообщение
Send me your code.
It has nothing to do with my code, I'm simply pointing out that as it is, there's multiple sections throughout the include that uses %e with "format" instead of "mysql_format" for directly escaping strings; but only mysql_format supports %e. Once I edited the include (in my case specifically; RowExistsEx2), my code worked perfectly.
Reply
#56

PHP код:
LoadPlayerBankCards(playerid)
{
    new 
p_name_inside_f[MAX_PLAYER_NAME], Query[164], DBResult:GetPlayerBankCards, Dialog_String[226];
    
    
GetPlayerName(playerid, p_name_inside_f, sizeof(p_name_inside_f));

    
format(Query, sizeof(Query), "SELECT * FROM `bank-cards` WHERE `username` = '%s'", DB_Escape(p_name_inside_f));

    
format(Dialog_String, sizeof(Dialog_String), "\tBaratis Saxeli\tTanxa\n");

    
GetPlayerBankCards = db_query(Users, Query);

    if(
db_num_rows(GetPlayerBankCards))
    {

        for(new 
i; i<db_num_rows(GetPlayerBankCards); i++)
        {
            new 
card_name[64], card_cash, card_id, cards_info[64];

            
db_get_field_assoc(GetPlayerBankCards, "cardname", card_name, sizeof(card_name));
            
card_cash = db_get_field_assoc_int(GetPlayerBankCards, "cash");
            
card_id = db_get_field_assoc_int(GetPlayerBankCards, "id");

            
p_bank_card[playerid][p_bank_card_loaded[playerid]][cash] = card_cash;
            
p_bank_card[playerid][p_bank_card_loaded[playerid]][b_c_id] = card_id;
            
strcat(p_bank_card[playerid][p_bank_card_loaded[playerid]][name], card_name);
            
p_bank_card_loaded[playerid]++;

            
format(cards_info, sizeof(cards_info), "\t%s\t%d\n", card_name, card_cash);
            
strcat(Dialog_String, cards_info);
            
            
db_next_row(GetPlayerBankCards);
        }
    }
    else
    {
        
SendClientMessage(playerid, -1, "Tqven Ar Gaqvt Sabanko Baratebi!");
    }
    
db_free_result(GetPlayerBankCards);

    
ShowPlayerDialog(playerid, 81, DIALOG_STYLE_TABLIST_HEADERS, "Sabanko Baratebi", Dialog_String, "Sworia", "Bugia");

    return 
1;    
} 
How can i make this using Easy MySQL?
Reply
#57

I have to say, it's best you stick to original MySQL. I've tried making a gamemode before with this include and not to be rude, it was pretty shit. I had to rewrite a 7k line code on MySQL then, and I've decided to never use this again.
Reply
#58

Quote:
Originally Posted by Amagida
Посмотреть сообщение
PHP код:
LoadPlayerBankCards(playerid)
{
    new 
p_name_inside_f[MAX_PLAYER_NAME], Query[164], DBResult:GetPlayerBankCards, Dialog_String[226];
    
    
GetPlayerName(playerid, p_name_inside_f, sizeof(p_name_inside_f));
    
format(Query, sizeof(Query), "SELECT * FROM `bank-cards` WHERE `username` = '%s'", DB_Escape(p_name_inside_f));
    
format(Dialog_String, sizeof(Dialog_String), "\tBaratis Saxeli\tTanxa\n");
    
GetPlayerBankCards = db_query(Users, Query);
    if(
db_num_rows(GetPlayerBankCards))
    {
        for(new 
i; i<db_num_rows(GetPlayerBankCards); i++)
        {
            new 
card_name[64], card_cash, card_id, cards_info[64];
            
db_get_field_assoc(GetPlayerBankCards, "cardname", card_name, sizeof(card_name));
            
card_cash = db_get_field_assoc_int(GetPlayerBankCards, "cash");
            
card_id = db_get_field_assoc_int(GetPlayerBankCards, "id");
            
p_bank_card[playerid][p_bank_card_loaded[playerid]][cash] = card_cash;
            
p_bank_card[playerid][p_bank_card_loaded[playerid]][b_c_id] = card_id;
            
strcat(p_bank_card[playerid][p_bank_card_loaded[playerid]][name], card_name);
            
p_bank_card_loaded[playerid]++;
            
format(cards_info, sizeof(cards_info), "\t%s\t%d\n", card_name, card_cash);
            
strcat(Dialog_String, cards_info);
            
            
db_next_row(GetPlayerBankCards);
        }
    }
    else
    {
        
SendClientMessage(playerid, -1, "Tqven Ar Gaqvt Sabanko Baratebi!");
    }
    
db_free_result(GetPlayerBankCards);
    
ShowPlayerDialog(playerid, 81, DIALOG_STYLE_TABLIST_HEADERS, "Sabanko Baratebi", Dialog_String, "Sworia", "Bugia");
    return 
1;    
} 
How can i make this using Easy MySQL?
PHP код:
LoadPlayerBankCards(playerid)
{
    new 
p_name_inside_f[MAX_PLAYER_NAME], Dialog_String[226];
    
GetPlayerName(playerid, p_name_inside_f, sizeof(p_name_inside_f));
    
format(Dialog_String, sizeof(Dialog_String), "\tBaratis Saxeli\tTanxa\n");
    if(
SQL::RowExistsEx("bank-cards", "username", p_name_inside_f)) 
    {    
        new 
handle = SQL::OpenEx(SQL::MREAD, "bank-cards", "username", p_name_inside_f); 
        
SQL::ReadRetrievedRows(handle, i)
        {
            
SQL::ReadString(handle, "cardname", p_bank_card[playerid][p_bank_card_loaded[playerid]][name], 64, i);
            
SQL::ReadInt(handle, "cash", p_bank_card[playerid][p_bank_card_loaded[playerid]][cash], i);
            
SQL::ReadInt(handle, "id", p_bank_card[playerid][p_bank_card_loaded[playerid]][b_c_id], i);    
            
format(cards_info, sizeof(cards_info), "\t%s\t%d\n", p_bank_card[playerid][p_bank_card_loaded[playerid]][name], p_bank_card[playerid][p_bank_card_loaded[playerid]][cash]);
            
strcat(Dialog_String, cards_info);            
        }
        
SQL::Close(handle);
    }
    else
    {
        
SendClientMessage(playerid, -1, "Tqven Ar Gaqvt Sabanko Baratebi!");
    }
    
ShowPlayerDialog(playerid, 81, DIALOG_STYLE_TABLIST_HEADERS, "Sabanko Baratebi", Dialog_String, "Sworia", "Bugia");
    return 
1;    
} 
Reply
#59

what about easy-sqlite arn't you developing that
Reply
#60

Quote:
Originally Posted by Max_Andolini
View Post
Version 3.7 released.

PHP Code:
Bugs solved.
Added insert options. (Engine, Charset etc.)
Added Charset function in SQL::Connect.
Added Null or not null option in AddTableColumn.
SQL::Connect(const host[], const user[], const password[], const database[], const charset[] = "latin5", debugging = 0, port = 3306, bool:autoreconnect = true, pool_size = 2);
new 
handle = SQL::Open(SQL::CREATE, "database", "engine default InnoDB", -1, "charset default latin5");
SQL::AddTableColumn(handle, const field_name[], SQL::datatypes: type = SQL_TYPE_INT, maxlength = 11, bool:null = false, bool:auto_increment = false, bool:setprimary = false, bool:setindex = false)
SQL::Close(handle); 
Great. Can we talk about how these still use the "%e" specifier using normal format instead of mysql_format still though?

PHP Code:
SQL::DeleteRowEx2
SQL
::GetStringEntryEx2
SQL
::t_GetStringEntryEx2
SQL
::GetIntEntryEx2
SQL
::GetFloatEntryEx2
SQL
::SetIntEntryEx2
SQL
::SetStringEntry2
SQL
::SetStringEntryEx2
SQL
::SetFloatEntryEx2
SQL
::RowExistsEx2
SQL
::DeleteRow3 
Meanwhile, normal format doesn't support "%e"; as shown here (https://sampwiki.blast.hk/wiki/Format):



The only one it does support is "%q" but that's irrelevant in this case.

Now just look at RowExistsEx2 from the latest version of this library:

PHP Code:
stock SQL::RowExistsEx2(const table[], const column_where[] = "", const row_identifier[], const column_where2[] = "", const row_identifier2[] = "", row_identifier3 = -1, MySQL:connectionHandle = MYSQL_DEFAULT_HANDLE)
{
    new 
query[SQL_FORM_LENGTH], query2[SQL_FORM_LENGTH], Cache:result, rows;
    
format(query, sizeof(query), "SELECT * FROM `%s` WHERE `%s`='%e'", table, column_where, row_identifier); // HERE.
    
if(!isnull(column_where2) && !isnull(row_identifier2) && row_identifier3 == -1)
    {
        
format(query2, sizeof(query2), " AND `%s`='%e'", column_where2, row_identifier2); // HERE AS WELL.
        
strcat(query, query2);
    }
    if(!
isnull(column_where2) && row_identifier3 != -1 && isnull(row_identifier2))
    {
        
format(query2, sizeof(query2), " AND `%s`='%d'", column_where2, row_identifier3);
        
strcat(query, query2);
    }
    
strcat(query, " ");
    
result = mysql_query(connectionHandle, query);
    if(
mysql_errno() != 0)
    {
        return 
SQL_Warning("Query could not be completed due to error: %s", query);
    }
    
cache_get_row_count(rows);
    
cache_delete(result);
    if(
rows > 0)
    {
        return 
rows;
    }
    return 
0;
} 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)