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
and sent to the API as is - then need to be validated.
- INSERT
- **STRUCTURE** http://server/{operation}/{db}/{table}/?values=1,2,3,4
- INSERT INTO {table} VALUES({val1}, {val2})
- validate number of fields and types
- 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
Sets:
*N/A*
self.error:
Returns:
*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}"
if self.sqlite_check_db(db):
self.sqlite_get_table_error = False
self.error = False
try:
conn = sqlite3.connect(db_file)
c = conn.cursor()
@@ -147,7 +147,7 @@ class select(object):
conn.commit()
conn.close()
except Exception as e:
self.sqlite_get_table_error = e
self.error = e
print(e)
result = False
return result
@@ -163,7 +163,9 @@ class select(object):
table and filters to retrieve the data by
Sets:
*N/A*
*self.sqlite_check_db_error:*
bool(): False if everything is OK
str(): error string
Returns:
*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"
result = False
else:
self.sqlite_check_db_error = f"DB: {db_file} does not exist"
#html_result = htmlize.read_html('error', '/templates/')
#result = html_result.format(_error=error)
self.status = f"DB: {db_file} does not exist"
result = False
return result
@@ -220,21 +220,21 @@ class select(object):
db = kwargs["schema"]
result = self.sqlite_get_table(db, '*', 'sqlite_master')
tables = self.sqlite_get_table(db, 'tbl_name', 'sqlite_master')
status = 'OK'
error = False
except Exception as e:
result = ''
status = f"ERROR: {e}"
error = f"ERROR: {e}"
self.html = htmlize.read_html('schema','/templates/')
self.html = self.html.format(
_db=db,
_schema=htmlize.tabelize(result),
_tables=htmlize.tabelize_links(tables),
_status=status
_status=error
)
tables = [table[0] for table in tables]
self.json.update({
"result": {"tables": tables},
"status": status
"error": error
})
elif 'table' in kwargs.keys():
# In case a table is defined, what are the values?
@@ -244,20 +244,20 @@ class select(object):
# TODO different values
try:
result = self.sqlite_get_table(db, values, table)
status = 'OK'
error = False
except Exception as e:
result = ''
status = f"ERROR: {e}"
error = f"ERROR: {e}"
self.html = htmlize.read_html('table','/templates/')
self.html = self.html.format(
_db=db,
_table=table,
_rows=htmlize.tabelize(result),
_status=status
_status=error
)
self.json.update({
"result": {"rows": result},
"status": status
"error": error
})
elif url.split('/')[-2] == 'select':
#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.json.update({
"result":{"databases": result},
"status": "OK"
"error": self.error
})
else:
result = htmlize.read_html('error', '/templates/')
@@ -511,7 +511,7 @@ class delete(object):
)
self.json.update({
"result":{"response": result},
"status": self.error
"error": self.error
})
except Exception as e:
print(str(e))