Insert into database \t \n -
MerryDeer - 14.07.2016
Hi,
I have some stuff where i need \t and \n can i write them into database? i don't use escaping because i know what i write. All is showing in dialog
Re: Insert into database \t \n -
AbyssMorgan - 14.07.2016
Write arbitrary data to the database you can be achieved by simple conversion:
PHP Code:
//Save example:
new tmpInput[256], tmpOutput[256 * 2];
format(tmpInput,sizeof tmpInput,"sdnajnda\n\tćłśą ...");
StringToHexString(tmpInput,tmpOutput);
//tmpOutput = "73646E616A6E64615C6E5C74E6B39CB9202E2E2E" - save this
//Load example:
new tmp_data[256], tmp_hexdata[256 * 2];
tmp_hexdata = "73646E616A6E64615C6E5C74E6B39CB9202E2E2E";
HexStringToString(tmp_hexdata,tmp_data);
//tmp_data = "sdnajnda\n\tćłśą ..."
Output data StringToHexString is two times greater than the input data.
Include:
ADM.inc
Re: Insert into database \t \n -
Vince - 14.07.2016
As far as I know it's perfectly possible to insert those characters into a database without resorting to methods like these. But I think the column needs to be set as TEXT, rather than CHAR or VARCHAR.
Re: Insert into database \t \n -
MerryDeer - 29.08.2016
tmpInput,
Primary text will not by changed?
Re: Insert into database \t \n -
AbyssMorgan - 29.08.2016
No .
Re: Insert into database \t \n -
MerryDeer - 29.08.2016
But this is bad because i'am saving about ~100rows, so if there lenght >8126 i get mysql error, mysql line too long or smth..
Re: Insert into database \t \n -
Stinged - 29.08.2016
What you can do is use special characters to represent \n and \t
For examplle, # for \n and $ for \t
And then once you have them stored, use this:
pawn Code:
new i;
while (string[i++] > '\0')
{
if (string[i] == '#')
string[i] = '\n';
else if (string[i] == '$')
string[i] = '\t';
}
Re: Insert into database \t \n -
MerryDeer - 29.08.2016
I think for \t, maybe i just can do spaces? how much spaces have \t?
Re: Insert into database \t \n -
BlackBank - 29.08.2016
If you want to use \t or \n just escape it(put an extra \ before it).
Example:
"Text message\\t goes here\\n"
Re: Insert into database \t \n -
Stinged - 29.08.2016
Quote:
Originally Posted by BlackBank3
If you want to use \t or \n just escape it(put an extra \ before it).
Example:
"Text message\\t goes here\\n"
|
Yeah but that doesn't actually work in dialogs.
\n is a single character in pawn, \n are two characters (\ and n) in a table.