Swedish letters fuck up parsing into SQL querry

WebFreak001 d.forum at webfreak.org
Tue Mar 24 08:47:37 UTC 2020


On Monday, 23 March 2020 at 15:15:12 UTC, Anders S wrote:
> On Monday, 23 March 2020 at 15:07:31 UTC, Adam D. Ruppe wrote:
>> On Monday, 23 March 2020 at 14:26:46 UTC, Anders S wrote:
>>> do you mean I should loop through each pos till 
>>> strlen(cellTab[CellIndex].name) to find "\0"?
>>
>> strlen is ok, that gives the answer itself. Just slice to that.
>>
>> cellTab[CellIndex].name[0 .. 
>> strlen(cellTab[CellIndex].name.ptr)]
>>
>> could do it. or
>>
>> size_t end = 0;
>> foreach(idx, ch; cellTab[CellIndex].name)
>>    if(ch == 0) {
>>         end = idx;
>>         break;
>>    }
>>
>> auto name = cellTab[CellIndex].name[0 .. end];
>>
>>
>> anything like that
>>
>>> How do you suggest I do the querry build then?
>>
>> how are you running it? using a lib or just generating a .sql 
>> file?
>
> Hi,
> I'm creating a connection to the db and conn.exec(sql)
> I think I'll try the foreach to find out if it works .... ( 
> tomorrow )

if you use mysql-native, use

conn.exec("UPDATE celldata SET name=?, ...", name);

where you can make a function for name =

/// Takes the data part from a fixed length string until a null 
terminator.
/// Returns: a slice of text until a null terminator or whole 
string in case there is none.
const(char)[] str(size_t n)(const(char)[n] text)
{
     // count until \0 (in bytes, so we can't cause utf decoding 
exception)
     auto end = text[].representation.countUntil(0);
     // return whole string if there is no \0, otherwise until \0
     return end == -1 ? text[] : text[0 .. end];
}

I think making your own function here instead of using to!string 
is what you want here. If you put in a char[20] into to!string, 
it will still return a string with the remaining characters being 
\0 characters.


More information about the Digitalmars-d-learn mailing list