PDA

View Full Version : SQL Help


Luke_James
17/08/2015, 04:14 PM
This code...


SQL_SaveLicenses(playerid)
{
if (!PlayerData[playerid][pLogged])
return 0;

static
query[768];

format(query, sizeof(query), "UPDATE `licenses` SET `licID` = '%d', `ownerID` = '%d', `issuerID` = '%d', `issueDate` = '%s' WHERE `ID` = '%d'",
LicenseData[playerid][licID],
LicenseData[playerid][ownerID],
LicenseData[targetid][issuerID],
LicenseData[playerid][issueDate]
}; // this line
mysql_function_query(g_iHandle, query, false, "", "");
return 1;
} // this line


Gives these errors...


error 010: invalid function or declaration
error 010: invalid function or declaration


The lines are highlighted, it's just the brackets

Beckett
17/08/2015, 04:20 PM
SQL_SaveLicenses(playerid)
{
if (!PlayerData[playerid][pLogged])
return 0;

static
query[768];

format(query, sizeof(query), "UPDATE `licenses` SET `licID` = '%d', `ownerID` = '%d', `issuerID` = '%d', `issueDate` = '%s' WHERE `ID` = '%d'",
LicenseData[playerid][licID],
LicenseData[playerid][ownerID],
LicenseData[targetid][issuerID],
LicenseData[playerid][issueDate]
}; // ----> What is this semicolon? Remove it.
mysql_function_query(g_iHandle, query, false, "", "");
return 1;
}

arad55
17/08/2015, 04:26 PM
SQL_SaveLicenses(playerid)
{
if (!PlayerData[playerid][pLogged])
return 0;

static
query[768];

format(query, sizeof(query), "UPDATE `licenses` SET `licID` = '%d', `ownerID` = '%d', `issuerID` = '%d', `issueDate` = '%s' WHERE `ID` = '%d'",
LicenseData[playerid][licID],
LicenseData[playerid][ownerID],
LicenseData[targetid][issuerID],
LicenseData[playerid][issueDate]
}; // ----> What is this semicolon? Remove it.
mysql_function_query(g_iHandle, query, false, "", "");
return 1;
}


Nope, he should change the curly bracket to a round bracket (because it's meant to close the format function..).

Luke_James
17/08/2015, 04:27 PM
Well now I feel a bit stupid, can't believe I didn't see that

Luke_James
17/08/2015, 04:31 PM
Perhaps one of you could answer a question though?


static
query[768];


What should that number be? I've just put a random number in so I'm guessing it won't work as intended.

DarkLored
17/08/2015, 04:31 PM
SQL_SaveLicenses(playerid)
{
if (!PlayerData[playerid][pLogged])
return 0;

static
query[768];

format(query, sizeof(query), "UPDATE `licenses` SET `licID` = '%d', `ownerID` = '%d', `issuerID` = '%d', `issueDate` = '%s' WHERE `ID` = '%d'",
LicenseData[playerid][licID],
LicenseData[playerid][ownerID],
LicenseData[targetid][issuerID],
LicenseData[playerid][issueDate]
); // ----> What is this semicolon? Remove it.
mysql_function_query(g_iHandle, query, false, "", "");
return 1;
}


everything seems fine except the bracket that you used with a semi colon, to be honest you don't even need to do it that way and I don't think it works like that in Pawn try using a round bracket instead of a curly one to close formats.

Perhaps one of you could answer a question though?


static
query[768];


What should that number be? I've just put a random number in so I'm guessing it won't work as intended.

You count the character count and put how many characters were in the format including spaces.

Luke_James
17/08/2015, 04:36 PM
format(query, sizeof(query), "UPDATE `licenses` SET `licID` = '%d', `ownerID` = '%d', `issuerID` = '%d', `issueDate` = '%s' WHERE `ID` = '%d'",
LicenseData[playerid][licID],
LicenseData[playerid][ownerID],
LicenseData[targetid][issuerID],
LicenseData[playerid][issueDate]
);


All of that?

Beckett
17/08/2015, 04:38 PM
Nope, he should change the curly bracket to a round bracket (because it's meant to close the format function..).

I totally didn't see that, I apologize.

arad55
17/08/2015, 04:42 PM
format(query, sizeof(query), "UPDATE `licenses` SET `licID` = '%d', `ownerID` = '%d', `issuerID` = '%d', `issueDate` = '%s' WHERE `ID` = '%d'",
LicenseData[playerid][licID],
LicenseData[playerid][ownerID],
LicenseData[targetid][issuerID],
LicenseData[playerid][issueDate]
);


All of that?

Whatever you format here will be inserted into `query`. If your intended query is longer than 767 characters, it won't send the full query. Though, your array length should be fine for such short query.

Luke_James
17/08/2015, 04:43 PM
Whatever you format here will be inserted into `query`. If your intended query is longer than 767 characters, it won't send the full query. Though, your array length should be fine for such short query.

So it just has to be longer than the query itself, not exact?

arad55
17/08/2015, 04:46 PM
So it just has to be longer than the query itself, not exact?

It doesn't have to be exact, nor you have the ability to make it exact, because dynamic array sizes are not supported as far as I remember.

Vince
17/08/2015, 04:50 PM
The length of "UPDATE `licenses` SET `licID` = '%d', `ownerID` = '%d', `issuerID` = '%d', `issueDate` = '%s' WHERE `ID` = '%d'" is 111 characters. Subtract placeholders, that's 101. A number can be maximum 11 characters in length, so plus 44. That makes 145. IssueDate is probably going to be around 20 characters, so plus 20. That makes for a total optimal query length of 165.

True, calculating the optimal length is a lot of work, so it's fine if you put an estimate. However you shouldn't go overboard, like putting 768 when the total length is about a fifth of that.

Tamer
17/08/2015, 05:11 PM
At editors such as sublime text, atom, or notepad++ you can highlight and easily count how many chars a string has, I would recommend using one.