mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: x.vstring() instead of string(x) (#6102)
This commit is contained in:
@@ -116,7 +116,7 @@ pub fn (conn Connection) escape_string(s string) string {
|
||||
quote := byte(39) // single quote
|
||||
|
||||
C.mysql_real_escape_string_quote(conn.conn, to, s.str, len, quote)
|
||||
return string(to)
|
||||
return unsafe { to.vstring() }
|
||||
}
|
||||
|
||||
// set_option is used to set extra connect options and affect behavior for a connection.
|
||||
@@ -175,12 +175,12 @@ pub fn (conn Connection) info() string {
|
||||
|
||||
// get_host_info returns a string describing the connection.
|
||||
pub fn (conn Connection) get_host_info() string {
|
||||
return string(C.mysql_get_host_info(conn.conn))
|
||||
return unsafe { C.mysql_get_host_info(conn.conn).vstring() }
|
||||
}
|
||||
|
||||
// get_server_info returns the server version number as a string.
|
||||
pub fn (conn Connection) get_server_info() string {
|
||||
return string(C.mysql_get_server_info(conn.conn))
|
||||
return unsafe { C.mysql_get_server_info(conn.conn).vstring() }
|
||||
}
|
||||
|
||||
// get_server_version returns the server version number as an integer.
|
||||
@@ -192,7 +192,7 @@ pub fn (conn Connection) get_server_version() u64 {
|
||||
|
||||
// get_client_info returns client version information as a string.
|
||||
pub fn get_client_info() string {
|
||||
return string(C.mysql_get_client_info())
|
||||
return unsafe { C.mysql_get_client_info().vstring() }
|
||||
}
|
||||
|
||||
// get_client_version returns client version information as an integer.
|
||||
|
@@ -34,7 +34,7 @@ pub fn (r Result) rows() []Row {
|
||||
if rr[i] == 0 {
|
||||
row.vals << ''
|
||||
} else {
|
||||
row.vals << string(&byte(rr[i]))
|
||||
row.vals << mystring( byteptr(rr[i]) )
|
||||
}
|
||||
}
|
||||
rows << row
|
||||
@@ -64,12 +64,12 @@ pub fn (r Result) fields() []Field {
|
||||
orig_fields := C.mysql_fetch_fields(r.result)
|
||||
for i in 0..nr_cols {
|
||||
fields << Field{
|
||||
name: string(orig_fields[i].name)
|
||||
org_name: string(orig_fields[i].org_name)
|
||||
table: string(orig_fields[i].table)
|
||||
org_table: string(orig_fields[i].org_table)
|
||||
db: string(orig_fields[i].db)
|
||||
catalog: string(orig_fields[i].catalog)
|
||||
name: mystring(orig_fields[i].name)
|
||||
org_name: mystring(orig_fields[i].org_name)
|
||||
table: mystring(orig_fields[i].table)
|
||||
org_table: mystring(orig_fields[i].org_table)
|
||||
db: mystring(orig_fields[i].db)
|
||||
catalog: mystring(orig_fields[i].catalog)
|
||||
def: resolve_nil_str(orig_fields[i].def)
|
||||
length: orig_fields.length
|
||||
max_length: orig_fields.max_length
|
||||
|
@@ -2,7 +2,7 @@ module mysql
|
||||
|
||||
// get_error_msg returns error message from MySQL instance.
|
||||
fn get_error_msg(conn &C.MYSQL) string {
|
||||
return string(C.mysql_error(conn))
|
||||
return unsafe { C.mysql_error(conn).vstring() }
|
||||
}
|
||||
|
||||
// get_errno returns error number from MySQL instance.
|
||||
@@ -13,5 +13,12 @@ fn get_errno(conn &C.MYSQL) int {
|
||||
// resolve_nil_str returns empty string if passed value is a nil pointer.
|
||||
fn resolve_nil_str(ptr byteptr) string {
|
||||
if isnil(ptr) { return '' }
|
||||
return string(ptr)
|
||||
return unsafe { ptr.vstring() }
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn mystring(b byteptr) string {
|
||||
unsafe {
|
||||
return b.vstring()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user