Created
February 5, 2021 03:08
Star
You must be signed in to star a gist
mariadb-connector-python char type bytes if prepared
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import mariadb | |
| HOST = '' | |
| PORT = '' | |
| USER = '' | |
| PASSWORD = '' | |
| DATABASE = '' | |
| """ | |
| CREATE TABLE `t` ( | |
| `id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, | |
| `c` CHAR(8) NOT NULL, | |
| `tt` TINYTEXT NOT NULL, | |
| CONSTRAINT PRIMARY KEY (`id`)) | |
| ; | |
| INSERT INTO `t` (`c`, `tt`) VALUES ('12345678', '12345678'); | |
| INSERT INTO `t` (`c`, `tt`) VALUES ('deadbeef', 'cafebabe'); | |
| """ | |
| BASE_QRY = 'SELECT `c`, `tt` FROM `t`' | |
| WHERE_QRY = "SELECT `c`, `tt` FROM `t` WHERE `c` = '12345678'" | |
| PREPARED_QRY = 'SELECT `c`, `tt` FROM `t` WHERE `c` = ?' | |
| PREPARED_DATA = ('deadbeef',) | |
| def main(): | |
| conn = mariadb.connect(host=HOST, | |
| port=PORT, | |
| user=USER, | |
| password=PASSWORD, | |
| database=DATABASE) | |
| test_base(conn) | |
| test_where(conn) | |
| test_prepared(conn) | |
| conn.close() | |
| def test_base(conn): | |
| print('Testing BASE_QRY') | |
| cur = conn.cursor() | |
| cur.execute(BASE_QRY) | |
| for row in cur.fetchall(): | |
| print([type(c) for c in row]) | |
| cur.close() | |
| def test_where(conn): | |
| print('Testing WHERE_QRY') | |
| cur = conn.cursor() | |
| cur.execute(WHERE_QRY) | |
| for row in cur.fetchall(): | |
| print([type(c) for c in row]) | |
| cur.close() | |
| def test_prepared(conn): | |
| print('Testing PREPARED_QRY') | |
| cur = conn.cursor(prepared=True) | |
| cur.execute(PREPARED_QRY, PREPARED_DATA) | |
| for row in cur.fetchall(): | |
| print([type(c) for c in row]) | |
| cur.close() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment