diff options
Diffstat (limited to 'libmariadb/man/mysql_select_db.3')
-rw-r--r-- | libmariadb/man/mysql_select_db.3 | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/libmariadb/man/mysql_select_db.3 b/libmariadb/man/mysql_select_db.3 new file mode 100644 index 00000000..5a70797c --- /dev/null +++ b/libmariadb/man/mysql_select_db.3 @@ -0,0 +1,84 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_select_db" "3" "" "Version 3.3.1" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_select_db \- selects a database as default +.SS Synopsis +.IP +.nf +\f[C] +#include <mysql.h> + +int mysql_select_db(MYSQL * mysql, + const char * db); +\f[R] +.fi +.SS Description +.PP +Selects a database as default. +Returns zero on success, non\-zero on failure +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]db\f[R] \- the default database name +.SS Notes +.IP \[bu] 2 +To retrieve the name of the default database either execute the SQL +command \f[C]SELECT DATABASE()\f[R] or retrieve the value via +\f[B]mariadb_get_infov(3)\f[R] API function. +.IP \[bu] 2 +The default database can also be set by the db parameter in +\f[B]mysql_real_connect(3)\f[R]. +.SS Examples +.SS SQL +.IP +.nf +\f[C] +# switch to default database test +USE test; +# check default database +SELECT DATABASE(); ++\-\-\-\-\-\-\-\-\-\-\-\-+ +| database() | ++\-\-\-\-\-\-\-\-\-\-\-\-+ +| test | ++\-\-\-\-\-\-\-\-\-\-\-\-+ +\f[R] +.fi +.SS MariadDB Connector/C +.IP +.nf +\f[C] +static int set_default_db(MYSQL *mysql) +{ + int rc; + char *default_db; + + /* change default database to test */ + rc= mysql_select_db(mysql, \[dq]test\[dq]); + if (rc) + return rc; /* Error */ + + /* get the default database */ + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &default_db); + if (rc) + return rc; /* Error */ + + if (strcmp(\[dq]test\[dq], default_db) != NULL) + { + printf(\[dq]Wrong default database\[rs]n\[dq]); + return 1; + } + printf(\[dq]Default database: %s\[dq], default_db); + return 0; +} +\f[R] +.fi +.SS See also +.PP +\f[B]mysql_real_connect(3)\f[R] |