Problem writing to database

Just starting out? Need help? Post your questions and find answers here.
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: Problem writing to database

Post by Columbo »

Thank you Bisonte, Your code example seems to work although I am not clear as to what the "VALUES(?, ?)" is doing?

The database has 23 tables and the variable 'tablename' holds the value of the table that was selected from the ListView. It works fine.

Thanks again for the help and the code example.
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Problem writing to database

Post by citystate »

basically, what Bisonte's code is doing is with these lines,

Code: Select all

SetDatabaseString(#dbaseID, 0, name)
SetDatabaseString(#dbaseID, 1, code)
is assigning the strings "name" and "code" to the question marks in the query, without you having to alter the strings beforehand

nice fix btw, Bisonte, I never really got around to learning SetDatabaseString :)
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Problem writing to database

Post by Fangbeast »

And I forgot these were there or I would have done all my code that way instead of the huge concatenated string mess that I keep using.

Doesn't "SetDatabaseString" eliminate the need for escaping strings as it's a paramaterised insert etc?
Amateur Radio, D-STAR/VK3HAF
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: Problem writing to database

Post by Bisonte »

Fangbeast wrote:And I forgot these were there or I would have done all my code that way instead of the huge concatenated string mess that I keep using.

Doesn't "SetDatabaseString" eliminate the need for escaping strings as it's a paramaterised insert etc?
Sorry, I don't know exactly. But : Ever escape your strings if there are special characters in it.
I prepare the strings, that I set with SetDataBaseString. And I got no errors ;)
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Problem writing to database

Post by Fangbeast »

Sorry, I don't know exactly.
Wish I could remember it. Somewhere on the forum last year.
Amateur Radio, D-STAR/VK3HAF
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: Problem writing to database

Post by Columbo »

Thanks to all for the help on this one. It had me baffled!

Cheers
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Problem writing to database

Post by Demivec »

Fangbeast wrote:And I forgot these were there or I would have done all my code that way instead of the huge concatenated string mess that I keep using.

Doesn't "SetDatabaseString" eliminate the need for escaping strings as it's a paramaterised insert etc?
It does eliminate the need to escape a string. The strings aren't interpreted when does this way because they don't become part of the statement string; they are used as is to fill in the blanks, referenced by '?'.

This method also prevents clever or maliciously constructed strings from altering what the statement does according to what they contain. This was the unwanted side-effect columbo was having a problem with. It is caused by the total contents of the concatenated string having to be parsed to determine it's effect.
Post Reply