mysql: fix unwrapped unsafe code of mysql lib (#6680). (#6681)

pull/6688/head
Rolf Schmidt 2020-10-26 10:21:28 +01:00 committed by GitHub
parent 8e478e8909
commit 3f5be0f4fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -102,10 +102,8 @@ pub fn (conn Connection) tables(wildcard string) ?[]string {
// escape_string creates a legal SQL string for use in an SQL statement. // escape_string creates a legal SQL string for use in an SQL statement.
pub fn (conn Connection) escape_string(s string) string { pub fn (conn Connection) escape_string(s string) string {
len := C.strlen(s.str) to := malloc(2 * s.len + 1)
to := malloc(2 * len + 1) C.mysql_real_escape_string_quote(conn.conn, to, s.str, s.len, `\'`)
quote := byte(39) // single quote
C.mysql_real_escape_string_quote(conn.conn, to, s.str, len, quote)
return unsafe {to.vstring()} return unsafe {to.vstring()}
} }

View File

@ -31,10 +31,10 @@ pub fn (r Result) rows() []Row {
for rr := r.fetch_row(); rr; rr = r.fetch_row() { for rr := r.fetch_row(); rr; rr = r.fetch_row() {
mut row := Row{} mut row := Row{}
for i in 0 .. nr_cols { for i in 0 .. nr_cols {
if rr[i] == 0 { if unsafe {rr[i] == 0} {
row.vals << '' row.vals << ''
} else { } else {
row.vals << mystring(byteptr(rr[i])) row.vals << mystring(unsafe {byteptr(rr[i])})
} }
} }
rows << row rows << row
@ -63,7 +63,7 @@ pub fn (r Result) fields() []Field {
nr_cols := r.n_fields() nr_cols := r.n_fields()
orig_fields := C.mysql_fetch_fields(r.result) orig_fields := C.mysql_fetch_fields(r.result)
for i in 0 .. nr_cols { for i in 0 .. nr_cols {
fields << Field{ unsafe {fields << Field{
name: mystring(orig_fields[i].name) name: mystring(orig_fields[i].name)
org_name: mystring(orig_fields[i].org_name) org_name: mystring(orig_fields[i].org_name)
table: mystring(orig_fields[i].table) table: mystring(orig_fields[i].table)
@ -84,7 +84,7 @@ pub fn (r Result) fields() []Field {
decimals: orig_fields.decimals decimals: orig_fields.decimals
charsetnr: orig_fields.charsetnr charsetnr: orig_fields.charsetnr
type_: FieldType(orig_fields.@type) type_: FieldType(orig_fields.@type)
} }}
} }
return fields return fields
} }