v / vlib / db / mysql / utils.c.v
39 lines · 32 sloc · 970 bytes · 4a2f83b4bea4506de5d60ef459d19bcb0cb0a3ee
Raw
1module mysql
2
3// get_error_msg returns error message from MySQL instance.
4fn get_error_msg(conn &C.MYSQL) string {
5 return clone_mysql_cstring(C.mysql_error(conn))
6}
7
8// get_errno returns error number from MySQL instance.
9fn get_errno(conn &C.MYSQL) int {
10 return C.mysql_errno(conn)
11}
12
13// get_stmt_error_msg returns error message from a MySQL statement instance.
14fn get_stmt_error_msg(stmt &C.MYSQL_STMT) string {
15 return clone_mysql_cstring(&u8(C.mysql_stmt_error(stmt)))
16}
17
18// get_stmt_errno returns error number from a MySQL statement instance.
19fn get_stmt_errno(stmt &C.MYSQL_STMT) int {
20 return C.mysql_stmt_errno(stmt)
21}
22
23@[inline]
24fn clone_mysql_cstring(ptr &u8) string {
25 if isnil(ptr) {
26 return ''
27 }
28 return unsafe { tos_clone(ptr) }
29}
30
31// resolve_nil_str returns an empty string if passed value is a nil pointer.
32fn resolve_nil_str(ptr &u8) string {
33 return clone_mysql_cstring(ptr)
34}
35
36@[inline]
37fn mystring(b &u8) string {
38 return clone_mysql_cstring(b)
39}
40