Jump to content

how to insert ' character in sql

Recommended Posts


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& "')")


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

Thank . 


Edited by 123disconnect

Share this post

Link to post
Share on other sites

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

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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.