mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
db, json, time, term: change optional to result (#16201)
This commit is contained in:
@@ -37,7 +37,7 @@ pub mut:
|
||||
}
|
||||
|
||||
// connect - create a new connection to the MySQL server.
|
||||
pub fn (mut conn Connection) connect() ?bool {
|
||||
pub fn (mut conn Connection) connect() !bool {
|
||||
instance := C.mysql_init(conn.conn)
|
||||
conn.conn = C.mysql_real_connect(instance, conn.host.str, conn.username.str, conn.password.str,
|
||||
conn.dbname.str, conn.port, 0, conn.flag)
|
||||
@@ -50,7 +50,7 @@ pub fn (mut conn Connection) connect() ?bool {
|
||||
// query - make an SQL query and receive the results.
|
||||
// `query()` cannot be used for statements that contain binary data;
|
||||
// Use `real_query()` instead.
|
||||
pub fn (conn Connection) query(q string) ?Result {
|
||||
pub fn (conn Connection) query(q string) !Result {
|
||||
if C.mysql_query(conn.conn, q.str) != 0 {
|
||||
return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn))
|
||||
}
|
||||
@@ -75,7 +75,7 @@ pub fn (conn Connection) use_result() {
|
||||
// (Binary data may contain the `\0` character, which `query()`
|
||||
// interprets as the end of the statement string). In addition,
|
||||
// `real_query()` is faster than `query()`.
|
||||
pub fn (mut conn Connection) real_query(q string) ?Result {
|
||||
pub fn (mut conn Connection) real_query(q string) !Result {
|
||||
if C.mysql_real_query(conn.conn, q.str, q.len) != 0 {
|
||||
return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn))
|
||||
}
|
||||
@@ -84,7 +84,7 @@ pub fn (mut conn Connection) real_query(q string) ?Result {
|
||||
}
|
||||
|
||||
// select_db - change the default database for database queries.
|
||||
pub fn (mut conn Connection) select_db(dbname string) ?bool {
|
||||
pub fn (mut conn Connection) select_db(dbname string) !bool {
|
||||
if C.mysql_select_db(conn.conn, dbname.str) != 0 {
|
||||
return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn))
|
||||
}
|
||||
@@ -94,7 +94,7 @@ pub fn (mut conn Connection) select_db(dbname string) ?bool {
|
||||
// change_user - change the mysql user for the connection.
|
||||
// Passing an empty string for the `dbname` parameter, resultsg in only changing
|
||||
// the user and not changing the default database for the connection.
|
||||
pub fn (mut conn Connection) change_user(username string, password string, dbname string) ?bool {
|
||||
pub fn (mut conn Connection) change_user(username string, password string, dbname string) !bool {
|
||||
mut ret := true
|
||||
if dbname != '' {
|
||||
ret = C.mysql_change_user(conn.conn, username.str, password.str, dbname.str)
|
||||
@@ -124,7 +124,7 @@ pub fn (mut conn Connection) autocommit(mode bool) {
|
||||
// The `wildcard` parameter may contain the wildcard characters `%` or `_`.
|
||||
// If an empty string is passed, it will return all tables.
|
||||
// Calling `tables()` is similar to executing query `SHOW TABLES [LIKE wildcard]`.
|
||||
pub fn (conn &Connection) tables(wildcard string) ?[]string {
|
||||
pub fn (conn &Connection) tables(wildcard string) ![]string {
|
||||
cres := C.mysql_list_tables(conn.conn, wildcard.str)
|
||||
if isnil(cres) {
|
||||
return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn))
|
||||
@@ -157,7 +157,7 @@ pub fn (mut conn Connection) set_option(option_type int, val voidptr) {
|
||||
|
||||
// get_option - return the value of an option, settable by `set_option`.
|
||||
// https://dev.mysql.com/doc/c-api/5.7/en/mysql-get-option.html
|
||||
pub fn (conn &Connection) get_option(option_type int) ?voidptr {
|
||||
pub fn (conn &Connection) get_option(option_type int) !voidptr {
|
||||
ret := unsafe { nil }
|
||||
if C.mysql_get_option(conn.conn, option_type, &ret) != 0 {
|
||||
return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn))
|
||||
@@ -167,7 +167,7 @@ pub fn (conn &Connection) get_option(option_type int) ?voidptr {
|
||||
|
||||
// refresh - flush the tables or caches, or resets replication server
|
||||
// information. The connected user must have the `RELOAD` privilege.
|
||||
pub fn (mut conn Connection) refresh(options u32) ?bool {
|
||||
pub fn (mut conn Connection) refresh(options u32) !bool {
|
||||
if C.mysql_refresh(conn.conn, options) != 0 {
|
||||
return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn))
|
||||
}
|
||||
@@ -175,7 +175,7 @@ pub fn (mut conn Connection) refresh(options u32) ?bool {
|
||||
}
|
||||
|
||||
// reset - resets the connection, and clear the session state.
|
||||
pub fn (mut conn Connection) reset() ?bool {
|
||||
pub fn (mut conn Connection) reset() !bool {
|
||||
if C.mysql_reset_connection(conn.conn) != 0 {
|
||||
return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn))
|
||||
}
|
||||
@@ -184,7 +184,7 @@ pub fn (mut conn Connection) reset() ?bool {
|
||||
|
||||
// ping - pings a server connection, or tries to reconnect if the connection
|
||||
// has gone down.
|
||||
pub fn (mut conn Connection) ping() ?bool {
|
||||
pub fn (mut conn Connection) ping() !bool {
|
||||
if C.mysql_ping(conn.conn) != 0 {
|
||||
return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn))
|
||||
}
|
||||
@@ -224,7 +224,7 @@ pub fn (conn &Connection) get_server_version() u64 {
|
||||
|
||||
// dump_debug_info - instructs the server to write debugging information
|
||||
// to the error log. The connected user must have the `SUPER` privilege.
|
||||
pub fn (mut conn Connection) dump_debug_info() ?bool {
|
||||
pub fn (mut conn Connection) dump_debug_info() !bool {
|
||||
if C.mysql_dump_debug_info(conn.conn) != 0 {
|
||||
return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn))
|
||||
}
|
||||
|
Reference in New Issue
Block a user