Skip to content
Snippets Groups Projects
Unverified Commit 647453ca authored by Jangberry (Nomad-Debian)'s avatar Jangberry (Nomad-Debian)
Browse files

Avancement

parent 2c10b43d
No related branches found
No related tags found
No related merge requests found
.idea
.venv
\ No newline at end of file
......@@ -12,6 +12,7 @@
-- Database Section
-- ________________
DROP DATABASE IF EXISTS MAIN;
create database MAIN;
USE MAIN;
......
%% Cell type:markdown id: tags:
# SGBD Library
## Usage
1. Run a SQL server (for instance `docker run --name sgdb --env MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 -p 3306:3306 mariadb:latest`)
2. *You may need to* install the following package: `apt install libmariadb-dev`
3. Then, run the following code:
%% Cell type:code id: tags:
``` python
%pip install mariadb
import mariadb
```
%% Output
Requirement already satisfied: mariadb in ./.venv/lib/python3.10/site-packages (1.1.8)
Requirement already satisfied: packaging in ./.venv/lib/python3.10/site-packages (from mariadb) (23.2)
Note: you may need to restart the kernel to use updated packages.
%% Cell type:code id: tags:
``` python
mariaDB = mariadb.connect(
user="root",
host="172.17.0.2", # IP of the container
# host="172.0.0.1",
port=3306,
)
cur = mariaDB.cursor()
```
%% Cell type:markdown id: tags:
This code will apply the dll:
%% Cell type:code id: tags:
``` python
def exec_sql_file(cursor, sql_file):
statement = ""
for line in open(sql_file):
if line.startswith('--'):
continue
if not line.strip().endswith(';'):
statement = statement + line
else: # when you get a line ending in ';' then exec statement and reset for next statement
statement = statement + line
try:
cursor.execute(statement)
except (mariadb.OperationalError, mariadb.ProgrammingError) as e:
print("\n[WARN] MySQLError during execute statement \n\tArgs: '%s'" % (str(e.args)))
statement = ""
exec_sql_file(cur, "BE_SGBD_LIBRARY.ddl")
```
%% Cell type:markdown id: tags:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment