[SQLite] Incorrect query?!?
#1

Hey Guys... i have a litle problem...
So, the following. I have a record ... this is not read correctly.

as you can see does not work the whole query ... but why?
Here is my Code:
PHP Code:
public LoadBizz()
{
    new
        
DBResult:dbresult db_query(ServerDB"SELECT * FROM `Bizz`"),
        
rows db_num_rows(dbresult),
        
field[20],
        
time GetTickCount();
    if(!
rows) {
        return print(
"Es wurden keine Bizz in der Datenbank gefunden!");
    }
    for(new 
i=0i<rowsi++) {
        
db_get_field_assoc(dbresult"BizzID"fieldsizeof(field));                bInfo[i][ID]     = strval(field);
        
db_get_field_assoc(dbresult"Name"fieldsizeof(field));                 bInfo[i][Name]     = strval(field);
        
db_get_field_assoc(dbresult"Kasse"fieldsizeof(field));                bInfo[i][Kasse] = strval(field);
        
db_get_field_assoc(dbresult"PickupX"fieldsizeof(field));                 bInfo[i][X]     = strval(field);
        
db_get_field_assoc(dbresult"PickupY"fieldsizeof(field));                bInfo[i][Y]     = strval(field);
        
db_get_field_assoc(dbresult"PickupZ"fieldsizeof(field));                bInfo[i][Z]     = strval(field);
        
CreateBizzPickup(ibInfo[i][Name], bInfo[i][X], bInfo[i][Y], bInfo[i][Z]);
        
printf("BizzID:     "bInfo[i][ID]);
        
printf("Bizz Name:  "bInfo[i][Name]);
        
printf("Bizz Kasse: "bInfo[i][Kasse]);
        
printf("BizzX:      "bInfo[i][X]);
        
printf("BizzY:      "bInfo[i][Y]);
        
printf("BizzZ:      "bInfo[i][Z]);
        
db_next_row(dbresult);
    }
    
db_free_result(dbresult);
    
printf("Es wurden %d Businesse in %dms geladen!"rowsGetTickCount()-time);
    return 
1;

Reply
#2

First of all, you did not use any specifier in printf function.
Second of all, name should be string so don't use strval.
Coordinates are floats, so floatstr.
Reply
#3

Wow ... that was really really ... well .. uh stupid of me?
So now i become Warnings because the Tag Mismatch.

Code:
db_get_field_assoc(dbresult, "PickupX", field, sizeof(field)); 		bInfo[i][X] 	= floatstr(field);
db_get_field_assoc(dbresult, "PickupY", field, sizeof(field));		bInfo[i][Y] 	= floatstr(field);
db_get_field_assoc(dbresult, "PickupZ", field, sizeof(field));		bInfo[i][Z] 	= floatstr(field);
Reply
#4

You have X, Y and Z as integers in the enumerator used for bInfo. Coordinates though are supposed to be floats so it's recommended to change it (adding Float: tag).
Reply
#5

Okay, one little problem :S

Now it load's everything... but not the Name?
The 'name' has been recorded in the table as 'TEXT'
Code:
db_get_field_assoc(dbresult, "Name", field, sizeof(field)); 		bInfo[i][Name] 	= strval(field);
This is obviously not read correctly:/
Reply
#6

Name is a string so you shouldn't use strval:
pawn Code:
db_get_field_assoc(dbresult, "Name", bInfo[i][Name], 20);
Change 20 to the size you have in "Name" in the enum.
Reply
#7

Thank you now it works Perfectly
Reply
#8

I have another Problem :/

I save it as 'TEXT' in the Database and %s in the format string
Reply
#9

^^ Might be a problem when you set the label string in a 3D Text label.

Just to improve your loop:
pawn Code:
new i;
do
{
        db_get_field_assoc(dbresult, "BizzID", field, sizeof(field));                bInfo[i][ID]     = strval(field);
        db_get_field_assoc(dbresult, "Name", field, sizeof(field));                 bInfo[i][Name]     = strval(field);
        db_get_field_assoc(dbresult, "Kasse", field, sizeof(field));                bInfo[i][Kasse] = strval(field);
        db_get_field_assoc(dbresult, "PickupX", field, sizeof(field));                 bInfo[i][X]     = strval(field);
        db_get_field_assoc(dbresult, "PickupY", field, sizeof(field));                bInfo[i][Y]     = strval(field);
        db_get_field_assoc(dbresult, "PickupZ", field, sizeof(field));                bInfo[i][Z]     = strval(field);
        CreateBizzPickup(i, bInfo[i][Name], bInfo[i][X], bInfo[i][Y], bInfo[i][Z]);
        printf("BizzID:     ", bInfo[i][ID]);
        printf("Bizz Name:  ", bInfo[i][Name]);
        printf("Bizz Kasse: ", bInfo[i][Kasse]);
        printf("BizzX:      ", bInfo[i][X]);
        printf("BizzY:      ", bInfo[i][Y]);
        printf("BizzZ:      ", bInfo[i][Z]);

        i++;
}
while (db_next_row(dbresult));
And you should have a limit in this case because what if the rows are somehow greater than the MAX_BUSINESSES ?

@EDIT: For got to declare variable "i".
Reply
#10

I set the label with this:
Code:
new LabelTextSize[128];
format(LabelTextSize, sizeof(LabelTextSize), "Business Nummer: %d\n %s", BizzID,  BizzName);
Create3DTextLabel(LabelTextSize, COLOR_ORANGE, BizzX, BizzY, BizzZ+1, 40.0, 0, 0);
Reply
#11

Can you show how you used BizzName? You have the names already stored in bInfo[id_here][Name] so you can use this instead. Also VARCHAR with TEXT is the same thing.

@Gammix: There's no difference in the loops as he already got rows before. About the limit you are right. So either use inside the loop (at the top):
pawn Code:
if (i >= sizeof bInfo) break;
or you can just do:
pawn Code:
rows  = clamp(db_num_rows(dbresult), 0, sizeof bInfo - 1);
and change nothing to the for loop.
Reply
#12

I tried it but now i get nothing...
Maybe it's a Database fail?


Printed out in the Console:
Reply
#13

Have you tried a SQLite Database Browser to see if the inserted data are okay? I thought it printed the name correctly after this, didn't it?

A suggestion would also be to create 3D labels and suchs after loading directly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)