mysql issue

Shay

Well-Known Member
Licensed User
Longtime User
Hi

I am trying to add to the table some word with '
and the myysql does not like it
I cannot remove the ' and I must add the word as is
how can i overcome this issue

this is the code I am using:
SQL1.ExecNonQuery("UPDATE Table_User_Words SET Sounds_Like='" & TextBox_Sound_Like.Text & "',Sounds_Like_Replace='" & TextBox_Sound_Like_Replace.Text & "' WHERE Sounds_Like = '" & Delete_Row & "'")


Thanks
 

mc73

Well-Known Member
Licensed User
Longtime User
Sure this is mySQL? I think it's an sqLite query. If so, try using execNonQuery2. I think it's a very good choice.
 
Upvote 0

stefanobusetto

Active Member
Licensed User
Longtime User
Sorry the auto correction.
:)
I mean if ' is the string delimiter
You can put it twice inside a string
And yuo' ll get it single
 
Upvote 0

Penko

Active Member
Licensed User
Longtime User
Try logging your query. Then "right click", copy the line and try to manually execute it in MySQL(via PHPMyAdmin for example). It will tell you where the error is. For me this query is pretty much valid. Maybe it has to do with your fields having incorrect names.

You can't told us what the exact error you get is.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Try logging your query. Then "right click", copy the line and try to manually execute it in MySQL(via PHPMyAdmin for example). It will tell you where the error is. For me this query is pretty much valid. Maybe it has to do with your fields having incorrect names.

You can't told us what the exact error you get is.

Our friend is trying to insert a word starting with ', or so we understood. This thing, just as Stefano suggests, should be done by using a double '. At least this is how we usually see it in mySQL. Still, not quite sure that this cannot be done by simply using execNonQuery2. I haven't tested it.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
When i need to insert into database something with ' I do like this:

Example:
B4X:
UPDATE `my_databse` SET `Ime` = 'This is ''testme'' program',
`Link` = 'http://ccccccc',
`Ikona` = 'http://ccccccp.png' WHERE `my_databse`.`ID` =1 LIMIT 1

You see this testme. It has inserted into database so now is :
This is 'testme' program in
 
Upvote 0

Penko

Active Member
Licensed User
Longtime User
Such scenarios are to be escaped or double-quoted.

Therefore, he has to use--> '\'here is the text'.

Tested this on MySQL 5.0.51 and it inserts the value: 'here is the text

Edit: @pluton was faster. We provided enough solution. The easiest way is to test which works for your case because I think you are missing to share some information with us.
 
Last edited:
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
the problem is that when someone tries to insert the word:
don't
if fails
android.database.sqlite.SQLiteException: near "don": syntax error: , while compiling: UPDATE Table_User_Words SET Sounds_Like='don't',Sounds_Like_Replace='aa' WHERE Sounds_Like = 'bbb'

i just tried to use '' (2 x ')and it didn't help, I will try the other solutions
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Check also this thread, there is a suggestion of mine, plus one of Erel very similar to an earlier of mine here. I think the last one is the key to the solution.
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
thanks, this fixed the problem:

Dim aaa(3) As String
aaa(0)=TextBox_Sound_Like.Text
aaa(1)=TextBox_Sound_Like_Replace.Text
aaa(2)=Delete_Row
Dim queryString As String

queryString="UPDATE Table_User_Words SET Sounds_Like = ?, Sounds_Like_Replace = ? WHERE Sounds_Like = ? "

SQL1.execNonQuery2(queryString,Array As Object(aaa(0),aaa(1),aaa(2)))
 
Upvote 0
Top