Raised This Month: $32 Target: $400
 8% 

SQLite add strings?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eyal282
Veteran Member
Join Date: Aug 2011
Old 08-09-2018 , 06:27   SQLite add strings?
Reply With Quote #1

Format(sQuery, sizeof(sQuery), "UPDATE %s SET value = value + %s WHERE AuthId = \"%s\"", Name, Value, AuthId);

Given that the variable Value is a string and the column ( or row whatever it's called ) value is also a string, and given that the strings are nothing but numbers and floats, would sqlite allow such computing to occur or an error will be thrown?

The reason I don't want to create an integer is because I wanna make something easier to perform ( Trying to do something like clientprefs but for values that aren't preferences ) which will be convinient and the value is always a string.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-09-2018 , 06:32   Re: SQLite add strings?
Reply With Quote #2

Quote:
Originally Posted by eyal282 View Post
Format(sQuery, sizeof(sQuery), "UPDATE %s SET value = value + %s WHERE AuthId = \"%s\"", Name, Value, AuthId);

Given that the variable Value is a string and the column ( or row whatever it's called ) value is also a string, and given that the strings are nothing but numbers and floats, would sqlite allow such computing to occur or an error will be thrown?

The reason I don't want to create an integer is because I wanna make something easier to perform ( Trying to do something like clientprefs but for values that aren't preferences ) which will be convinient and the value is always a string.
value must be an int column to do column = column + value (or view as int that column in your plugin) and use '%s' with database escape for strings.
__________________
Ilusion9 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-09-2018 , 06:41   Re: SQLite add strings?
Reply With Quote #3

It works, but.

value = value + new value, \

Adds the existing value to the new value.

I belive this is what you want:

value = value + SPACE(1) + %s


@Ilusion9

You're incorrect, it's called string concatenation.

Last edited by mug1wara; 08-09-2018 at 06:43.
mug1wara is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 08-09-2018 , 08:22   Re: SQLite add strings?
Reply With Quote #4

Quote:
Originally Posted by mug1wara View Post
It works, but.

value = value + new value, \

Adds the existing value to the new value.

I belive this is what you want:

value = value + SPACE(1) + %s


@Ilusion9

You're incorrect, it's called string concatenation.
Curiousity will this work with floats and integers combined? Like if combining two ints result is int and combining two floats result is float and combining one of each result is float?

Edit: it works perfectly without SPACE(1), but what does SPACE(1) do?
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334

Last edited by eyal282; 08-09-2018 at 08:42.
eyal282 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-09-2018 , 08:45   Re: SQLite add strings?
Reply With Quote #5

Adds a space

Let's say you have a column that has the existing value of "Hello", and you want to add "Goodbye".
If you then add them together, it'll be "HelloGoodbye".

It's just my ocd that makes me put SPACE(1)
mug1wara is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-09-2018 , 08:58   Re: SQLite add strings?
Reply With Quote #6

Quote:
Originally Posted by mug1wara View Post
@Ilusion9

You're incorrect, it's called string concatenation.
I know what string concatenation is.

value = value + %s (string column) is not equal with value = value + %d (int column)
__________________
Ilusion9 is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 08-09-2018 , 10:16   Re: SQLite add strings?
Reply With Quote #7

Quote:
Originally Posted by Ilusion9 View Post
I know what string concatenation is.

value = value + %s (string column) is not equal with value = value + %d (int column)
But why does it work perfectly in my DB Browser? Will it break apart when tried in a sourcemod query?
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-09-2018 , 11:13   Re: SQLite add strings?
Reply With Quote #8

According to SQLite spec, you can use the || operator to concatenate strings.
__________________
klippy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode