Insert into database \t \n
#1

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
Reply
#2

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
Reply
#3

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.
Reply
#4

tmpInput,

Primary text will not by changed?
Reply
#5

No .
Reply
#6

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..
Reply
#7

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';
}
Reply
#8

I think for \t, maybe i just can do spaces? how much spaces have \t?
Reply
#9

If you want to use \t or \n just escape it(put an extra \ before it).

Example:
"Text message\\t goes here\\n"
Reply
#10

Quote:
Originally Posted by BlackBank3
View Post
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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)