[SQLite] Incorrect query?!? -
SQLite - 12.04.2016
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=0; i<rows; i++) {
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]);
db_next_row(dbresult);
}
db_free_result(dbresult);
printf("Es wurden %d Businesse in %dms geladen!", rows, GetTickCount()-time);
return 1;
}
Re: [SQLite] Incorrect query?!? -
Konstantinos - 12.04.2016
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.
Re: [SQLite] Incorrect query?!? -
SQLite - 12.04.2016
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);
Re: [SQLite] Incorrect query?!? -
Konstantinos - 12.04.2016
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).
Re: [SQLite] Incorrect query?!? -
SQLite - 12.04.2016
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:/
Re: [SQLite] Incorrect query?!? -
Konstantinos - 12.04.2016
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.
Re: [SQLite] Incorrect query?!? -
SQLite - 12.04.2016
Thank you
now it works Perfectly
Re: [SQLite] Incorrect query?!? -
SQLite - 12.04.2016
I have another Problem :/
I save it as 'TEXT' in the Database and %s in the format string
Re: [SQLite] Incorrect query?!? -
Gammix - 12.04.2016
^^ 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".
Re: [SQLite] Incorrect query?!? -
SQLite - 13.04.2016
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);
Re: [SQLite] Incorrect query?!? -
Konstantinos - 13.04.2016
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.
Re: [SQLite] Incorrect query?!? -
SQLite - 13.04.2016
I tried it but now i get nothing...
Maybe it's a Database fail?
Printed out in the Console:
Re: [SQLite] Incorrect query?!? -
Konstantinos - 13.04.2016
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.