Skip to content

Commit

Permalink
Trying out variations on implementing the esc function in pure Swift
Browse files Browse the repository at this point in the history
  • Loading branch information
FahimF committed Jul 31, 2014
1 parent f00148c commit 6de03c8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions SQLiteDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,13 @@ class SQLiteDB {
// SQL escape string - original version, does not work correctly at the moment
func esc2(str: String)->String {
println("SQLiteDB - Original string: \(str)")
let args = getVaList([str])
let cstr = sqlite3_vmprintf("%Q", args)
var buf = UnsafePointer<Int8>.alloc(100)
let args = getVaList([str as CVarArg])
let cstr = sqlite3_vsnprintf(100, buf, "%Q", args)
// let cstr = sqlite3_vmprintf("%Q", args)
println("SQLiteDB - Escaped result: \(cstr), buffer: \(buf.memory)")
let sql = String.fromCString(cstr)
sqlite3_free(cstr)
// sqlite3_free(cstr)
println("SQLiteDB - Escaped string: \(sql)")
return sql!
}
Expand Down

0 comments on commit 6de03c8

Please sign in to comment.