SQLite functions!
#1

Hello There,

What is the difference between db_get_field_assoc and db_get_field ?

Note: please give examples with explanation (not defines)
Reply
#2

db_get_field gets a value from the specified field ID, while db_get_field_assoc gets a value from the specified field name.

https://sampwiki.blast.hk/wiki/Db_get_field
https://sampwiki.blast.hk/wiki/Db_get_field_assoc
Reply
#3

db_get_field fetches the field content passed by a field number.

db_get_field_assoc fetches the field that matches the fieldname you passed.

In theory, db_get_field_assoc should be slower than db_get_field, because db_get_field_assoc has to loop through the fields and compare names.
Reply
#4

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
db_get_field fetches the field content passed by a field number.

db_get_field_assoc fetches the field that matches the fieldname you passed.

In theory, db_get_field_assoc should be slower than db_get_field, because db_get_field_assoc has to loop through the fields and compare names.
Quote:
Originally Posted by Emmet_
Посмотреть сообщение
db_get_field gets a value from the specified field ID, while db_get_field_assoc gets a value from the specified field name.

https://sampwiki.blast.hk/wiki/Db_get_field
https://sampwiki.blast.hk/wiki/Db_get_field_assoc
Thank you both (rep++)
Reply
#5

any one knows why this code crashes my server?

PHP код:
LoadData(playerid)
{
    new 
DBResultqueryszQuery[200], szPlayerName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridszPlayerNameMAX_PLAYER_NAME);
    new 
Field[20], x[20], y[20], z[20], a[20];
    
format(szQuerysizeof(szQuery), "SELECT * from players WHERE NAME = '%s'"DB_Escape(szPlayerName));
    
query db_query(someDBszQuery);
    if(
db_num_rows(query))
    {
        
db_get_field_assoc(query"CASH"Field30);
        
GivePlayerMoney(playeridstrval(Field));
        
//---
        
db_get_field_assoc(query"ADMINLEVEL"Field30);
        
pData[playerid][pAdminLevel] = strval(Field);
        
//---
        
db_get_field_assoc(query"LEVEL"Field30);
        
SetPlayerScore(playeridstrval(Field));
           
//---
           
db_get_field_assoc(query"GENDER"Field30);
        
pData[playerid][pGender] = strval(Field);
        
//---
        
db_get_field_assoc(query"AGE"Field30);
        
pData[playerid][pAge] = strval(Field);
        
//---
        
db_get_field_assoc(query"SKIN"Field30);
        
SetPlayerSkin(playeridstrval(Field));
        new    
skin =  strval(Field);
        
//---
          
db_get_field_assoc(query"GUN1"Field30);
        
GivePlayerWeapon(playeridstrval(Field), pData[playerid][pAmmo1]);
         
//---
          
db_get_field_assoc(query"GUN2"Field30);
        
GivePlayerWeapon(playeridstrval(Field), pData[playerid][pAmmo2]);
         
//---
         
db_get_field_assoc(query"GUN3"Field30);
        
GivePlayerWeapon(playeridstrval(Field), pData[playerid][pAmmo3]);
         
//---
          
db_get_field_assoc(query"AMMO1"Field30);
        
SetPlayerAmmo(playeridpData[playerid][pGun1],  strval(Field));
          
//---
           
db_get_field_assoc(query"AMMO2"Field30);
        
SetPlayerAmmo(playeridpData[playerid][pGun2],  strval(Field));
        
//---
        
db_get_field_assoc(query"AMMO3"Field30);
        
SetPlayerAmmo(playeridpData[playerid][pGun3],  strval(Field));
        
//---
        
db_get_field_assoc(query"POS_X"x30);
        
db_get_field_assoc(query"POS_Y"y30);
        
db_get_field_assoc(query"POS_Z"z30);
        
db_get_field_assoc(query"POS_A"a30);
        
pData[playerid][pPos_x] = strval(x);
        
pData[playerid][pPos_y] = strval(y);
        
pData[playerid][pPos_z] = strval(z);
        
pData[playerid][pPos_a] = strval(a);
        
SetSpawnInfo(playerid0skinpData[playerid][pPos_x], pData[playerid][pPos_y], pData[playerid][pPos_z], pData[playerid][pPos_a], pData[playerid][pGun1], pData[playerid][pAmmo1],pData[playerid][pGun2], pData[playerid][pAmmo2], pData[playerid][pGun3], pData[playerid][pAmmo3]);
        
SpawnPlayer(playerid);
        
//if(pData[playerid][pGun1] != 0 || pData[playerid][pGun2] != 0 || pData[playerid][pGun3] != 0) { return SendClientMessage(playerid, COLOR_YELLOW, "[TIPS]:"COL_GREEN" /getweapons to restore back your weapons");
    
}
    else {
        
SendClientMessage(playeridCOLOR_RED"ERROR(001): Couldn't Load Your DatBase");
    }
    return 
1;

Reply
#6

I think it's because you're creating the string "Field" with a cell-size of 20, when the length in db_get_field_assoc is 30.

EDIT: try de-bugging
Reply
#7

then what shall I do?
Reply
#8

Change your fetching strings to.
PHP код:
new Field[30], x[30], y[30], z[30], a[30]; 
and replace this in your script as well
PHP код:
pData[playerid][pPos_x] = floatstr(x); 
        
pData[playerid][pPos_y] = floatstr(y); 
        
pData[playerid][pPos_z] = floatstr(z); 
        
pData[playerid][pPos_a] = floatstr(a); 
Reply
#9

sorry, but still I receive a crash
Reply
#10

a ya 3am nawy t3ml a?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)