tina4-python 0.2.30__tar.gz → 0.2.32__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tina4_python-0.2.30 → tina4_python-0.2.32}/PKG-INFO +1 -1
- {tina4_python-0.2.30 → tina4_python-0.2.32}/pyproject.toml +1 -1
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Database.py +52 -8
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Migration.py +8 -2
- {tina4_python-0.2.30 → tina4_python-0.2.32}/README.md +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Auth.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Constant.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/DatabaseResult.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Debug.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Env.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Localization.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Messages.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/MiddleWare.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Request.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Response.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Router.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Session.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/ShellColors.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Swagger.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Template.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/Webserver.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/__init__.py +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/messages.pot +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/css/readme.md +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/favicon.ico +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/images/403.png +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/images/404.png +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/images/logo.png +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/images/readme.md +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/js/readme.md +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/js/tina4helper.js +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/swagger/index.html +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/swagger/oauth2-redirect.html +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/templates/errors/403.twig +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/templates/errors/404.twig +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/templates/readme.md +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/translations/en/LC_MESSAGES/messages.mo +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/translations/en/LC_MESSAGES/messages.po +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/translations/fr/LC_MESSAGES/messages.mo +0 -0
- {tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/translations/fr/LC_MESSAGES/messages.po +0 -0
|
@@ -16,7 +16,7 @@ from tina4_python.DatabaseResult import DatabaseResult
|
|
|
16
16
|
class Database:
|
|
17
17
|
SQLITE = "sqlite3"
|
|
18
18
|
FIREBIRD = "firebird.driver"
|
|
19
|
-
MYSQL = "mysql"
|
|
19
|
+
MYSQL = "mysql.connector"
|
|
20
20
|
POSTGRES = "postgres"
|
|
21
21
|
|
|
22
22
|
def __init__(self, _connection_string, _username="", _password=""):
|
|
@@ -39,8 +39,7 @@ class Database:
|
|
|
39
39
|
self.dba = self.database_module.connect(self.database_path)
|
|
40
40
|
self.port = None
|
|
41
41
|
self.host = None
|
|
42
|
-
|
|
43
|
-
if self.database_engine == self.FIREBIRD:
|
|
42
|
+
elif self.database_engine == self.FIREBIRD:
|
|
44
43
|
# <host>/<port>:<file>
|
|
45
44
|
temp_params = self.database_path.split(":", 1)
|
|
46
45
|
host_port = temp_params[0].split("/", 1)
|
|
@@ -57,10 +56,32 @@ class Database:
|
|
|
57
56
|
user=self.username,
|
|
58
57
|
password=self.password
|
|
59
58
|
)
|
|
59
|
+
else:
|
|
60
|
+
temp_params = self.database_path.split(":", 1)
|
|
61
|
+
host_port = temp_params[0].split("/", 1)
|
|
62
|
+
self.host = host_port[0]
|
|
63
|
+
if len(host_port) > 1:
|
|
64
|
+
self.port = int(host_port[1])
|
|
65
|
+
else:
|
|
66
|
+
self.port = 0
|
|
67
|
+
|
|
68
|
+
self.database_path = temp_params[1]
|
|
69
|
+
|
|
70
|
+
self.dba = self.database_module.connect(
|
|
71
|
+
database=self.database_path,
|
|
72
|
+
port=self.port,
|
|
73
|
+
host=self.host,
|
|
74
|
+
user=self.username,
|
|
75
|
+
password=self.password
|
|
76
|
+
)
|
|
60
77
|
|
|
61
78
|
Debug("DATABASE:", self.database_module, self.host, self.port, self.database_path, self.username,
|
|
62
79
|
Constant.TINA4_LOG_DEBUG)
|
|
63
80
|
|
|
81
|
+
def database_exists(self, database_name):
|
|
82
|
+
|
|
83
|
+
return True
|
|
84
|
+
|
|
64
85
|
def current_timestamp(self):
|
|
65
86
|
"""
|
|
66
87
|
Gets the current timestamp based on the database being used
|
|
@@ -103,14 +124,15 @@ class Database:
|
|
|
103
124
|
"""
|
|
104
125
|
# modify the select statement for limit and skip
|
|
105
126
|
if self.database_engine == self.FIREBIRD:
|
|
106
|
-
sql = f"select first {limit} skip {skip} * from ({sql})"
|
|
127
|
+
sql = f"select first {limit} skip {skip} * from ({sql}) as t"
|
|
107
128
|
elif self.database_engine == self.SQLITE:
|
|
108
|
-
sql = f"select * from ({sql}) limit {skip},{limit}"
|
|
129
|
+
sql = f"select * from ({sql}) as t limit {skip},{limit}"
|
|
109
130
|
else:
|
|
110
|
-
sql = f"select * from ({sql}) limit {skip},{limit}"
|
|
131
|
+
sql = f"select * from ({sql}) as t limit {skip},{limit}"
|
|
111
132
|
|
|
112
133
|
cursor = self.dba.cursor()
|
|
113
134
|
try:
|
|
135
|
+
sql = self.parse_place_holders(sql)
|
|
114
136
|
cursor.execute(sql, params)
|
|
115
137
|
return self.get_database_result(cursor)
|
|
116
138
|
except Exception as e:
|
|
@@ -126,6 +148,7 @@ class Database:
|
|
|
126
148
|
:return:
|
|
127
149
|
"""
|
|
128
150
|
# Calling the fetch method with limit as 1 and returning the result
|
|
151
|
+
sql = self.parse_place_holders(sql)
|
|
129
152
|
record = self.fetch(sql, params=params, limit=1, skip=skip)
|
|
130
153
|
if record.error is None and record.count == 1:
|
|
131
154
|
data = {}
|
|
@@ -141,6 +164,19 @@ class Database:
|
|
|
141
164
|
else:
|
|
142
165
|
return None
|
|
143
166
|
|
|
167
|
+
def parse_place_holders(self, sql):
|
|
168
|
+
"""
|
|
169
|
+
Sanitizes a sql statement to replace param chars with the appropriate placeholders
|
|
170
|
+
MYSQL expects %s and firebird, posgres and sqlite expect ?
|
|
171
|
+
:param sql:
|
|
172
|
+
:return:
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
if self.database_engine == self.MYSQL:
|
|
176
|
+
return sql.replace("?", "%s")
|
|
177
|
+
else:
|
|
178
|
+
return sql.replace("%s", "?")
|
|
179
|
+
|
|
144
180
|
def execute(self, sql, params=()):
|
|
145
181
|
"""
|
|
146
182
|
Execute a query based on a sql statement
|
|
@@ -148,13 +184,18 @@ class Database:
|
|
|
148
184
|
:param params:
|
|
149
185
|
:return:
|
|
150
186
|
"""
|
|
187
|
+
sql = self.parse_place_holders(sql)
|
|
151
188
|
cursor = self.dba.cursor()
|
|
152
189
|
# Running an execute statement and committing any changes to the database
|
|
153
190
|
try:
|
|
154
191
|
cursor.execute(sql, params)
|
|
155
|
-
if "returning" in sql:
|
|
192
|
+
if "returning" in sql.lower():
|
|
156
193
|
return self.get_database_result(cursor)
|
|
157
194
|
else:
|
|
195
|
+
# see if we are mysql and if we are insert statement to get the last record
|
|
196
|
+
if "insert" in sql.lower() and self.database_engine == self.MYSQL:
|
|
197
|
+
return DatabaseResult([{"id": cursor.lastrowid}], [], None)
|
|
198
|
+
|
|
158
199
|
# On success return an empty result set with no error
|
|
159
200
|
return DatabaseResult(None, [], None)
|
|
160
201
|
except Exception as e:
|
|
@@ -169,6 +210,7 @@ class Database:
|
|
|
169
210
|
:param params:
|
|
170
211
|
:return:
|
|
171
212
|
"""
|
|
213
|
+
sql = self.parse_place_holders(sql)
|
|
172
214
|
cursor = self.dba.cursor()
|
|
173
215
|
# Running an execute statement and committing any changes to the database
|
|
174
216
|
try:
|
|
@@ -246,7 +288,9 @@ class Database:
|
|
|
246
288
|
|
|
247
289
|
sql = f"INSERT INTO {table_name} ({columns}) VALUES ({placeholders})"
|
|
248
290
|
|
|
249
|
-
|
|
291
|
+
if self.database_engine == self.FIREBIRD or self.database_engine == self.SQLITE:
|
|
292
|
+
sql += f" returning ({primary_key})"
|
|
293
|
+
|
|
250
294
|
records = DatabaseResult()
|
|
251
295
|
for record in data:
|
|
252
296
|
record = self.sanitize(record)
|
|
@@ -18,8 +18,14 @@ def migrate(dba, delimiter=";", migration_folder="migrations"):
|
|
|
18
18
|
:param migration_folder: Alternative folder for migrations
|
|
19
19
|
:return:
|
|
20
20
|
"""
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
if dba.database_engine == dba.MYSQL:
|
|
23
|
+
dba.execute(
|
|
24
|
+
"create table if not exists tina4_migration(id integer not null auto_increment, description varchar(200) default '', content text, error_message text, passed integer default 0, primary key(id))")
|
|
25
|
+
else:
|
|
26
|
+
dba.execute(
|
|
27
|
+
"create table if not exists tina4_migration(id integer not null, description varchar(200) default '', content blob, error_message blob, passed integer default 0, primary key(id))")
|
|
28
|
+
|
|
23
29
|
|
|
24
30
|
Debug("Migrations found ", tina4_python.root_path + os.sep + migration_folder, Constant.TINA4_LOG_INFO)
|
|
25
31
|
dir_list = os.listdir(tina4_python.root_path + os.sep + migration_folder)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/public/swagger/oauth2-redirect.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/translations/en/LC_MESSAGES/messages.mo
RENAMED
|
File without changes
|
{tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/translations/en/LC_MESSAGES/messages.po
RENAMED
|
File without changes
|
{tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/translations/fr/LC_MESSAGES/messages.mo
RENAMED
|
File without changes
|
{tina4_python-0.2.30 → tina4_python-0.2.32}/tina4_python/translations/fr/LC_MESSAGES/messages.po
RENAMED
|
File without changes
|