1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

mysql: add select_db method

This commit is contained in:
Don Alfons Nisnoni 2020-01-11 20:25:59 +08:00 committed by Alexander Medvednikov
parent 0a33c9ebf5
commit f7f5f43c48

View File

@ -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)
}