Constants are declared in mariadb.constants module.
For using constants of various types, they have to be imported first:
from mariadb.constants import *
MariaDB capability flags.
These flags are used to check the capabilities both of a MariaDB server or the client applicaion.
Capability flags are defined in module mariadb.constants.CAPABILIY
Since version 1.1.4
import mariadb
from mariadb.constants import *
# connection parameters
conn_params= {
"user" : "example_user",
"password" : "GHbe_Su3B8",
"host" : "localhost"
}
with mariadb.connect(**conn_params) as connection:
# test if LOAD DATA LOCAL INFILE is supported
if connection.server_capabilities & CAPABILITY.LOCAL_FILES:
print("Server supports LOCAL INFILE")
Output:
Server supports LOCAL INFILE
MariaDB capability flags.
These flags are used to check the capabilities both of a MariaDB server or the client applicaion.
Capability flags are defined in module mariadb.constants.CLIENT
Since version 1.1.0, deprecated in 1.1.4
Cursor constants are used for server side cursors. Currently only read only cursor is supported.
Cursor constants are defined in module mariadb.constants.CURSOR.
Since version 1.1.0
This is the default setting (no cursor)
Will create a server side read only cursor. The cursor is a forward cursor, which means it is not possible to scroll back.
Using ERR constants instead of error numbers make the code more readable. Error constants are defined in constants.ERR module
Since version 1.1.2
import mariadb
from mariadb.constants import *
# connection parameters
conn_params= {
"user" : "example_user",
"password" : "wrong_password",
"host" : "localhost"
}
# try to establish a connection
try:
connection= mariadb.connect(**conn_params)
except mariadb.OperationalError as Err:
if Err.errno == ERR.ER_ACCESS_DENIED_ERROR:
print("Access denied. Wrong password!")
Output:
Access denied. Wrong password!
MariaDB FIELD_FLAG Constants
These constants represent the various field flags. As an addition to the DBAPI 2.0 standard (PEP-249) these flags are returned as eighth element of the cursor description attribute.
Field flags are defined in module mariadb.constants.FIELD_FLAG
Since version 1.1.0
column is defined as not NULL
column is (part of) a primary key
column is (part of) a unique key
column is (part of) a key
column contains a binary object
numeric column is defined as unsigned
column has zerofill attribute
column is a binary
column is defined as enum
column is an auto_increment column
column is defined as time stamp
column is defined as SET
column hasn’t a default value
column will be set to current timestamp on UPDATE
column contains numeric value
column is part of a key
MariaDB FIELD_TYPE Constants
These constants represent the field types supported by MariaDB. The field type is returned as second element of cursor description attribute.
Field types are defined in module mariadb.constants.FIELD_TYPE
column type is TINYINT (1-byte integer)
column type is SMALLINT (2-byte integer)
column tyoe is INT (4-byte integer)
column type is FLOAT (4-byte single precision)
column type is DOUBLE (8-byte double precision)
column type is NULL
column tyoe is TIMESTAMP
column tyoe is BIGINT (8-byte Integer)
column type is MEDIUMINT (3-byte Integer)
column type is DATE
column type is TIME
column type is YEAR
column type is YEAR
column type is BIT
column type is JSON
column type is DECIMAL
column type is ENUM
column type is SET
column type is TINYBLOB (max. length of 255 bytes)
column type is MEDIUMBLOB (max. length of 16,777,215 bytes)
column type is LONGBLOB (max. length 4GB bytes)
column type is BLOB (max. length of 65.535 bytes)
column type is VARCHAR (variable length)
column type is CHAR (fixed length)
column type is GEOMETRY
Indicator values are used in executemany() method of cursor class to indicate special values when connected to a MariaDB server 10.2 or newer.
indicates a NULL value
indicates to use default value of column
indicates to ignore value for column for UPDATE statements. If set, the column will not be updated.
indicates not to update the entire row.
For internal use only
For internal use only
The STATUS constants are used to check the server status of the current connection.
Since version 1.1.0
Example:
cursor.callproc("my_storedprocedure", (1,"foo"))
if (connection.server_status & STATUS.SP_OUT_PARAMS): print("retrieving output parameters from store procedure") ... else: print("retrieving data from stored procedure") ....
Pending transaction
Server operates in autocommit mode
The result from last executed statement contained two or more result sets which can be retrieved by cursors nextset() method.
The last executed statement didn’t use a good index.
The last executed statement didn’t use an index.
The last executed statement opened a server side cursor.
For server side cursors this flag indicates end of a result set.
The current database in use was dropped and there is no default database for the connection anymore.
Indicates that SQL mode NO_BACKSLASH_ESCAPE is active, which means that the backslash character ‘' becomes an ordinary character.
The previously executed statement was slow (and needs to be optimized).
The current result set contains output parameters of a stored procedure.
The session status has been changed.
SQL mode ANSI_QUOTES is active,
This page is covered by the Creative Commons Attribution 3.0 license.