New gitea

This commit is contained in:
Milan Toman
2021-01-20 14:40:22 +01:00
parent d1ca046f64
commit b018b30b79
3 changed files with 18 additions and 17 deletions

View File

@@ -28,6 +28,7 @@ https://cherrypy.org/
- Conditions operators and values can obviously be merged to one statement - Conditions operators and values can obviously be merged to one statement
and sent to the API as is - then need to be validated. and sent to the API as is - then need to be validated.
- INSERT - INSERT
- **STRUCTURE** http://server/{operation}/{db}/{table}/?values=1,2,3,4
- INSERT INTO {table} VALUES({val1}, {val2}) - INSERT INTO {table} VALUES({val1}, {val2})
- validate number of fields and types - validate number of fields and types
- error handling and tracebacks - error handling and tracebacks

Binary file not shown.

View File

@@ -126,7 +126,7 @@ class select(object):
table and filters to retrieve the data by table and filters to retrieve the data by
Sets: Sets:
*N/A* self.error:
Returns: Returns:
*result:* tuple(), rows from table, or DB schema as a tuple *result:* tuple(), rows from table, or DB schema as a tuple
@@ -137,7 +137,7 @@ class select(object):
''' '''
db_file = f"{config._ROOT}/{config._DB_PATH}/{db}" db_file = f"{config._ROOT}/{config._DB_PATH}/{db}"
if self.sqlite_check_db(db): if self.sqlite_check_db(db):
self.sqlite_get_table_error = False self.error = False
try: try:
conn = sqlite3.connect(db_file) conn = sqlite3.connect(db_file)
c = conn.cursor() c = conn.cursor()
@@ -147,7 +147,7 @@ class select(object):
conn.commit() conn.commit()
conn.close() conn.close()
except Exception as e: except Exception as e:
self.sqlite_get_table_error = e self.error = e
print(e) print(e)
result = False result = False
return result return result
@@ -163,7 +163,9 @@ class select(object):
table and filters to retrieve the data by table and filters to retrieve the data by
Sets: Sets:
*N/A* *self.sqlite_check_db_error:*
bool(): False if everything is OK
str(): error string
Returns: Returns:
*result:* tuple(), rows from table, or DB schema as a tuple *result:* tuple(), rows from table, or DB schema as a tuple
@@ -183,9 +185,7 @@ class select(object):
self.sqlite_check_db_error = f"DB: {db_file} is not a standard file" self.sqlite_check_db_error = f"DB: {db_file} is not a standard file"
result = False result = False
else: else:
self.sqlite_check_db_error = f"DB: {db_file} does not exist" self.status = f"DB: {db_file} does not exist"
#html_result = htmlize.read_html('error', '/templates/')
#result = html_result.format(_error=error)
result = False result = False
return result return result
@@ -220,21 +220,21 @@ class select(object):
db = kwargs["schema"] db = kwargs["schema"]
result = self.sqlite_get_table(db, '*', 'sqlite_master') result = self.sqlite_get_table(db, '*', 'sqlite_master')
tables = self.sqlite_get_table(db, 'tbl_name', 'sqlite_master') tables = self.sqlite_get_table(db, 'tbl_name', 'sqlite_master')
status = 'OK' error = False
except Exception as e: except Exception as e:
result = '' result = ''
status = f"ERROR: {e}" error = f"ERROR: {e}"
self.html = htmlize.read_html('schema','/templates/') self.html = htmlize.read_html('schema','/templates/')
self.html = self.html.format( self.html = self.html.format(
_db=db, _db=db,
_schema=htmlize.tabelize(result), _schema=htmlize.tabelize(result),
_tables=htmlize.tabelize_links(tables), _tables=htmlize.tabelize_links(tables),
_status=status _status=error
) )
tables = [table[0] for table in tables] tables = [table[0] for table in tables]
self.json.update({ self.json.update({
"result": {"tables": tables}, "result": {"tables": tables},
"status": status "error": error
}) })
elif 'table' in kwargs.keys(): elif 'table' in kwargs.keys():
# In case a table is defined, what are the values? # In case a table is defined, what are the values?
@@ -244,20 +244,20 @@ class select(object):
# TODO different values # TODO different values
try: try:
result = self.sqlite_get_table(db, values, table) result = self.sqlite_get_table(db, values, table)
status = 'OK' error = False
except Exception as e: except Exception as e:
result = '' result = ''
status = f"ERROR: {e}" error = f"ERROR: {e}"
self.html = htmlize.read_html('table','/templates/') self.html = htmlize.read_html('table','/templates/')
self.html = self.html.format( self.html = self.html.format(
_db=db, _db=db,
_table=table, _table=table,
_rows=htmlize.tabelize(result), _rows=htmlize.tabelize(result),
_status=status _status=error
) )
self.json.update({ self.json.update({
"result": {"rows": result}, "result": {"rows": result},
"status": status "error": error
}) })
elif url.split('/')[-2] == 'select': elif url.split('/')[-2] == 'select':
#No DB, nor table is defined, list DBs in config._DB_PATH #No DB, nor table is defined, list DBs in config._DB_PATH
@@ -266,7 +266,7 @@ class select(object):
self.html += htmlize.tabelize_links(result) self.html += htmlize.tabelize_links(result)
self.json.update({ self.json.update({
"result":{"databases": result}, "result":{"databases": result},
"status": "OK" "error": self.error
}) })
else: else:
result = htmlize.read_html('error', '/templates/') result = htmlize.read_html('error', '/templates/')
@@ -511,7 +511,7 @@ class delete(object):
) )
self.json.update({ self.json.update({
"result":{"response": result}, "result":{"response": result},
"status": self.error "error": self.error
}) })
except Exception as e: except Exception as e:
print(str(e)) print(str(e))