mysql: migrate connection flags to enum instead of const, fix example (#7803)
parent
7f776bfd29
commit
e943d03298
|
@ -1,15 +1,18 @@
|
|||
// import mysql
|
||||
|
||||
// fn main() {
|
||||
// conn := mysql.connect('localhost', 'root', '', 'mysql')
|
||||
// res := conn.query('show tables')
|
||||
// for row in res.rows() {
|
||||
// println(row.vals.join(', '))
|
||||
// }
|
||||
// res.free()
|
||||
// conn.close()
|
||||
// }
|
||||
import mysql
|
||||
|
||||
fn main() {
|
||||
|
||||
mut conn := mysql.Connection{
|
||||
host: 'localhost'
|
||||
port: 3306
|
||||
username: 'root'
|
||||
password: ''
|
||||
dbname: 'mysql'
|
||||
}
|
||||
conn.connect() ?
|
||||
res := conn.query('show tables') ?
|
||||
for row in res.rows() {
|
||||
println(row.vals.join(', '))
|
||||
}
|
||||
res.free()
|
||||
conn.close()
|
||||
}
|
||||
|
|
|
@ -1,23 +1,5 @@
|
|||
module mysql
|
||||
|
||||
// MYSQL CONNECT FLAGS
|
||||
pub const (
|
||||
// CAN_HANDLE_EXPIRED_PASSWORDS = C.CAN_HANDLE_EXPIRED_PASSWORDS
|
||||
client_compress = C.CLIENT_COMPRESS
|
||||
client_found_rows = C.CLIENT_FOUND_ROWS
|
||||
client_ignore_sigpipe = C.CLIENT_IGNORE_SIGPIPE
|
||||
client_ignore_space = C.CLIENT_IGNORE_SPACE
|
||||
client_interactive = C.CLIENT_INTERACTIVE
|
||||
client_local_files = C.CLIENT_LOCAL_FILES
|
||||
client_multi_results = C.CLIENT_MULTI_RESULTS
|
||||
client_multi_statements = C.CLIENT_MULTI_STATEMENTS
|
||||
client_no_schema = C.CLIENT_NO_SCHEMA
|
||||
client_odbc = C.CLIENT_ODBC
|
||||
// client_optional_resultset_metadata = C.CLIENT_OPTIONAL_RESULTSET_METADATA
|
||||
client_ssl = C.CLIENT_SSL
|
||||
client_remember_options = C.CLIENT_REMEMBER_OPTIONS
|
||||
)
|
||||
|
||||
// MYSQL REFRESH FLAGS
|
||||
pub const (
|
||||
refresh_grant = u32(C.REFRESH_GRANT)
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
module mysql
|
||||
|
||||
|
||||
// Values for the capabilities flag bitmask used by the MySQL protocol.
|
||||
// See more on https://dev.mysql.com/doc/dev/mysql-server/latest/group__group__cs__capabilities__flags.html#details
|
||||
pub enum ConnectionFlag {
|
||||
// CAN_HANDLE_EXPIRED_PASSWORDS = C.CAN_HANDLE_EXPIRED_PASSWORDS
|
||||
client_compress = C.CLIENT_COMPRESS
|
||||
client_found_rows = C.CLIENT_FOUND_ROWS
|
||||
client_ignore_sigpipe = C.CLIENT_IGNORE_SIGPIPE
|
||||
client_ignore_space = C.CLIENT_IGNORE_SPACE
|
||||
client_interactive = C.CLIENT_INTERACTIVE
|
||||
client_local_files = C.CLIENT_LOCAL_FILES
|
||||
client_multi_results = C.CLIENT_MULTI_RESULTS
|
||||
client_multi_statements = C.CLIENT_MULTI_STATEMENTS
|
||||
client_no_schema = C.CLIENT_NO_SCHEMA
|
||||
client_odbc = C.CLIENT_ODBC
|
||||
// client_optional_resultset_metadata = C.CLIENT_OPTIONAL_RESULTSET_METADATA
|
||||
client_ssl = C.CLIENT_SSL
|
||||
client_remember_options = C.CLIENT_REMEMBER_OPTIONS
|
||||
}
|
||||
|
||||
// TODO: Documentation
|
||||
pub struct Connection {
|
||||
mut:
|
||||
|
@ -10,7 +30,7 @@ pub mut:
|
|||
username string
|
||||
password string
|
||||
dbname string
|
||||
flag int
|
||||
flag ConnectionFlag
|
||||
}
|
||||
|
||||
// connect connects to a MySQL server.
|
||||
|
|
Loading…
Reference in New Issue