From f7f5f43c4827aba166b94c2cd4d96c60eb79dac3 Mon Sep 17 00:00:00 2001 From: Don Alfons Nisnoni Date: Sat, 11 Jan 2020 20:25:59 +0800 Subject: [PATCH] mysql: add select_db method --- vlib/mysql/mysql.v | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vlib/mysql/mysql.v b/vlib/mysql/mysql.v index f915ee09cd..8843df3935 100644 --- a/vlib/mysql/mysql.v +++ b/vlib/mysql/mysql.v @@ -28,6 +28,7 @@ struct C.MYSQL_RES fn C.mysql_init(mysql &C.MYSQL) &C.MYSQL fn C.mysql_real_connect(mysql &C.MYSQL, host byteptr, user byteptr, passwd byteptr, db byteptr, port u32, unix_socket byteptr, clientflag u64) &C.MYSQL fn C.mysql_query(mysql &C.MYSQL, q byteptr) int +fn C.mysql_select_db(mysql &C.MYSQL, db byteptr) int fn C.mysql_error(mysql &C.MYSQL) byteptr fn C.mysql_errno(mysql &C.MYSQL) int fn C.mysql_num_fields(res &C.MYSQL_RES) int @@ -67,6 +68,14 @@ pub fn (db DB) escape_string(s string) string { return string(to) } +pub fn (db DB) select_db(dbname string) ?bool { + ret := mysql_select_db(db.conn, dbname.str) + if ret != 0 { + return error_with_code(get_error_msg(db.conn), get_errno(db.conn)) + } + return true +} + pub fn (db DB) close() { C.mysql_close(db.conn) } @@ -107,4 +116,3 @@ fn get_error_msg(conn &C.MYSQL) string { fn get_errno(conn &C.MYSQL) int { return C.mysql_errno(conn) } -