123disconnect

how to insert ' character in sql

4 posts in this topic

#1 ·  Posted (edited)

Example code 

$adoCon = ObjCreate("ADODB.Connection")
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 1
$adoRs.LockType = 3
$adoCon.Open("Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & @ScriptDir&"\data.mdb;") ;Use this line if using MS Access 2003 and lower

;$string = "ABCDEF"     ; not error
$string = "AB'CDEF"     ; error

$adoCon.execute( "INSERT INTO STR VALUES ('" &$string& "')")

$adoCon.Close

Help me  this code. Get error if ' character in $string  

Thank . 

 

Edited by 123disconnect

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

From SQLite.au3 :

Func _SQLite_FastEscape($sString)
    If IsNumber($sString) Then $sString = String($sString) ; don't raise error if passing a numeric parameter
    If Not IsString($sString) Then Return SetError(1, 0, "")
    Return ("'" & StringReplace($sString, "'", "''", 0, $STR_CASESENSE) & "'")  ;$STR_CASESENSE = 1
EndFunc   ;==>_SQLite_FastEscape

 

Edited by mikell

Share this post


Link to post
Share on other sites

ok. Thank all 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now