finish database query. but some codec is wrong
This commit is contained in:
parent
6fb9235b1b
commit
bb775e4b20
|
@ -218,7 +218,7 @@ BOOL envDatabase::init() {
|
||||||
if (result != SQLITE_OK) return FALSE;
|
if (result != SQLITE_OK) return FALSE;
|
||||||
|
|
||||||
result = sqlite3_exec(db,
|
result = sqlite3_exec(db,
|
||||||
"CREATE TABLE op([funcptr] INTEGER, [in1_guid] TEXT, [in2_guid] TEXT, [out_guid] TEXT, [op_guid] INTEGER, [op_name] TEXT, [op_code] INTEGER);",
|
"CREATE TABLE op([funcptr] INTEGER, [in1_guid] TEXT, [in2_guid] TEXT, [out_guid] TEXT, [op_guid] TEXT, [op_name] TEXT, [op_code] INTEGER);",
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
if (result != SQLITE_OK) return FALSE;
|
if (result != SQLITE_OK) return FALSE;
|
||||||
result = sqlite3_exec(db,
|
result = sqlite3_exec(db,
|
||||||
|
|
|
@ -22,6 +22,13 @@ def get_db():
|
||||||
db = g._database = sqlite3.connect(CustomConfig.decorated_db)
|
db = g._database = sqlite3.connect(CustomConfig.decorated_db)
|
||||||
return db
|
return db
|
||||||
|
|
||||||
|
def get_env():
|
||||||
|
env = getattr(g, '_envDatabase', None)
|
||||||
|
if env is None:
|
||||||
|
env = g._envDatabase = sqlite3.connect(CustomConfig.env_db)
|
||||||
|
env.text_factory = lambda x: x.decode(CustomConfig.database_encoding)
|
||||||
|
return env
|
||||||
|
|
||||||
@app.teardown_appcontext
|
@app.teardown_appcontext
|
||||||
def close_connection(exception):
|
def close_connection(exception):
|
||||||
db = getattr(g, '_database', None)
|
db = getattr(g, '_database', None)
|
||||||
|
@ -39,14 +46,25 @@ def block_pin_decoder2(target):
|
||||||
return [vab['name'], vab['type']]
|
return [vab['name'], vab['type']]
|
||||||
|
|
||||||
# =============================================route
|
# =============================================route
|
||||||
|
|
||||||
|
# =========== default
|
||||||
|
|
||||||
@app.route('/', methods=['GET'])
|
@app.route('/', methods=['GET'])
|
||||||
def nospecHandle():
|
def nospecHandle():
|
||||||
return redirect(url_for('indexHandle'))
|
return redirect(url_for('indexHandle'))
|
||||||
|
|
||||||
|
# =========== misc page
|
||||||
|
|
||||||
@app.route('/help', methods=['GET'])
|
@app.route('/help', methods=['GET'])
|
||||||
def helpMainHandle():
|
def helpMainHandle():
|
||||||
return render_template("help.html")
|
return render_template("help.html")
|
||||||
|
|
||||||
|
@app.route('/about', methods=['GET'])
|
||||||
|
def aboutHandle():
|
||||||
|
return render_template("about.html", static_icon = url_for('static', filename='icon.png'))
|
||||||
|
|
||||||
|
# =========== help page
|
||||||
|
|
||||||
@app.route('/help/<path:scriptPath>', methods=['GET'])
|
@app.route('/help/<path:scriptPath>', methods=['GET'])
|
||||||
def helpHandle(scriptPath):
|
def helpHandle(scriptPath):
|
||||||
if scriptPath == 'converter':
|
if scriptPath == 'converter':
|
||||||
|
@ -64,9 +82,47 @@ def helpHandle(scriptPath):
|
||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
@app.route('/about', methods=['GET'])
|
@app.route('/help/env', methods=['POST'])
|
||||||
def aboutHandle():
|
def envQueryHandle():
|
||||||
return render_template("about.html", static_icon = url_for('static', filename='icon.png'))
|
basicReturn = {
|
||||||
|
"status": False,
|
||||||
|
"overflow": False,
|
||||||
|
"data": []
|
||||||
|
}
|
||||||
|
|
||||||
|
# check tag
|
||||||
|
queryTag = request.form['tag'];
|
||||||
|
if queryTag not in ss.legalEnvQueryKey:
|
||||||
|
return basicReturn
|
||||||
|
|
||||||
|
cur = get_env().cursor()
|
||||||
|
#try:
|
||||||
|
readyData = json.loads(request.form['data'])
|
||||||
|
fieldLength = len(readyData.keys())
|
||||||
|
if fieldLength == 0:
|
||||||
|
cur.execute("SELECT * FROM {}".format(queryTag))
|
||||||
|
else:
|
||||||
|
whereStatement = '&&'.join(map(lambda x: "([" + x + "] = ?)", readyData.keys()))
|
||||||
|
cur.execute("SELECT * FROM {} WHERE ({})".format(queryTag, whereStatement), list(readyData.values()))
|
||||||
|
|
||||||
|
# iterate
|
||||||
|
counter = 0
|
||||||
|
for i in cur.fetchall():
|
||||||
|
if counter == 100:
|
||||||
|
basicReturn['overflow'] = True
|
||||||
|
break
|
||||||
|
basicReturn['data'].append(i)
|
||||||
|
counter+=1
|
||||||
|
|
||||||
|
basicReturn['status'] = True
|
||||||
|
#except Exception as ex:
|
||||||
|
# basicReturn['status'] = False
|
||||||
|
# basicReturn['overflow'] = False
|
||||||
|
# basicReturn['data'] = []
|
||||||
|
|
||||||
|
return basicReturn
|
||||||
|
|
||||||
|
# =========== index
|
||||||
|
|
||||||
@app.route('/index', methods=['GET'])
|
@app.route('/index', methods=['GET'])
|
||||||
def indexHandle():
|
def indexHandle():
|
||||||
|
@ -81,6 +137,8 @@ def indexHandle():
|
||||||
|
|
||||||
return render_template('index.html', scripts = data)
|
return render_template('index.html', scripts = data)
|
||||||
|
|
||||||
|
# =========== viewer
|
||||||
|
|
||||||
@app.route('/viewer/<path:scriptPath>', methods=['GET'])
|
@app.route('/viewer/<path:scriptPath>', methods=['GET'])
|
||||||
def viewerHandle(scriptPath):
|
def viewerHandle(scriptPath):
|
||||||
|
|
||||||
|
@ -154,5 +212,4 @@ def moveHandle(target):
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
|
|
|
@ -22,5 +22,61 @@ envDatabaseList = (
|
||||||
{"name": "Message",
|
{"name": "Message",
|
||||||
"queryKey": "msg",
|
"queryKey": "msg",
|
||||||
"data": (("index", "0", "(Integer) Message index"),
|
"data": (("index", "0", "(Integer) Message index"),
|
||||||
("name", "OnClick", "(String) Message name"))}
|
("name", "OnClick", "(String) Message name"))},
|
||||||
|
{"name": "Operation",
|
||||||
|
"queryKey": "op",
|
||||||
|
"data": (("funcptr", "615841344", "(Integer) Operation function memory location"),
|
||||||
|
("in1_guid", "1910468930,-1003023558", "(String) Input parameter 1 guid"),
|
||||||
|
("in2_guid", "-1411304621,-1568456412", "(String) Input parameter 2 guid"),
|
||||||
|
("out_guid", "450177678,1584666912", "(String) Output parameter guid"),
|
||||||
|
("op_guid", "869034825,898181163", "(String) Operation guid"),
|
||||||
|
("op_name", "Addition", "(String) Operation name"),
|
||||||
|
("op_code", "51", "(Integer) Operation code"))},
|
||||||
|
{"name": "Parameter",
|
||||||
|
"queryKey": "param",
|
||||||
|
"data": (("index", "0", "(Integer) Parameter index"),
|
||||||
|
("guid", "481363808,1100959941", "(String) Parameter guid"),
|
||||||
|
("derived_from", "0,0", "(String) The parameter guid deriving this parameter"),
|
||||||
|
("type_name", "None", "(String) Parameter name"),
|
||||||
|
("default_size", "4", "(Integer) Default size"),
|
||||||
|
("func_CreateDefault", "604002966", "(Integer) CreateDefault function memory location"),
|
||||||
|
("func_Delete", "604003366", "(Integer) Delete function memory location"),
|
||||||
|
("func_SaveLoad", "603996047", "(Integer) SaveLoad function memory location"),
|
||||||
|
("func_Check", "0", "(Integer) Check function memory location"),
|
||||||
|
("func_Copy", "604002468", "(Integer) Copy function memory location"),
|
||||||
|
("func_String", "0", "(Integer) String function memory location"),
|
||||||
|
("func_UICreator", "619055248", "(Integer) UICreator function memory location"),
|
||||||
|
("creator_dll_index", "-1", "(Integer) The id of the dll defining this parameter"),
|
||||||
|
("creator_plugin_index", "-1", "(Integer) The id of the plugin defining this parameter"),
|
||||||
|
("dw_param", "0", "(Integer) An application reserved DWORD for placing parameter type specific data"),
|
||||||
|
("dw_flags", "133", "(Integer) Flags specifying special settings for this parameter type"),
|
||||||
|
("cid", "0", "(Integer) Special case for parameter types that refer to CKObjects => corresponding class ID of the object"),
|
||||||
|
("saver_manager", "1181355948,0", "(String) Int Manager guid"))},
|
||||||
|
{"name": "Plugin",
|
||||||
|
"queryKey": "plugin",
|
||||||
|
"data": (("dll_index", "18", "(Integer) Dll index"),
|
||||||
|
("dll_name", "E:\\Virtools\\Plugins\\ImageReader.dll", "(String) Dll name"),
|
||||||
|
("plugin_index", "2", "(Integer) Plugin index"),
|
||||||
|
("category", "Bitmap Readers", "(String) Plugin category"),
|
||||||
|
("active", "1", "(Integer) For manager and Render engines TRUE if a manager was created, for other plugins this value is not used"),
|
||||||
|
("needed_by_file", "0", "(Integer) When saving a file TRUE if at least one object needs this plugin"),
|
||||||
|
("guid", "1632248895,1132147523", "(String) Plugin guid"),
|
||||||
|
("desc", "Windows Bitmap", "(String) Plugin description"),
|
||||||
|
("author", "Virtools", "(String) Plugin author"),
|
||||||
|
("summary", "Windows Bitmap", "(String) Plugin summary"),
|
||||||
|
("version", "1", "(Integer) Plugin version"),
|
||||||
|
("func_init", "103354496", "(Integer) Init function memory location"),
|
||||||
|
("func_exit", "624432336", "(Integer) Exit function memory location"))},
|
||||||
|
{"name": "Variable",
|
||||||
|
"queryKey": "variable",
|
||||||
|
"data": (("name", "3D XML/ExportVersion", "(String) Variable name"),
|
||||||
|
("description", "Version of exported 3DXML", "(String) Variable description"),
|
||||||
|
("flags", "4", "(Integer) Variable flags"),
|
||||||
|
("type", "1", "(Integer) Variable type"),
|
||||||
|
("representation", "enum:0= 3DXML 3.0; 1= 3DXML 4.0", "(String) The representation (ie the input format) of a variable type"),
|
||||||
|
("data", " 3DXML 3.0", "(String) Variable data"))}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
legalEnvQueryKey = list(map(lambda x: x['queryKey'], envDatabaseList))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,45 @@
|
||||||
function doQuery(fieldIndex, queryTag) {
|
function doQuery(fieldIndex, queryTag) {
|
||||||
;
|
// collect data
|
||||||
|
var readyData = {};
|
||||||
|
$("#queryTable_" + fieldIndex + " tr:not(:first-child)").each(function() {
|
||||||
|
var isEnabled = $(this).find(":nth-child(1) input").prop("checked");
|
||||||
|
if (!isEnabled) return;
|
||||||
|
|
||||||
|
var fieldName = $(this).find(":nth-child(2)").attr("queryName");
|
||||||
|
var fieldValue = $(this).find(":nth-child(3) input").val();
|
||||||
|
|
||||||
|
readyData[fieldName] = fieldValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
var jsonData = JSON.stringify(readyData);
|
||||||
|
|
||||||
|
// raise post
|
||||||
|
$.post(window.location,
|
||||||
|
{
|
||||||
|
tag: queryTag,
|
||||||
|
data: jsonData
|
||||||
|
},
|
||||||
|
function (data, status) {
|
||||||
|
// remove data
|
||||||
|
$("#resultTable_" + fieldIndex + " tr:not(:first-child)").remove();
|
||||||
|
|
||||||
|
// check
|
||||||
|
if (!data['status']) {
|
||||||
|
alert("Fail to query!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check overflow
|
||||||
|
if (data['overflow']) $("#resultTableOverflow_" + fieldIndex).show();
|
||||||
|
else $("#resultTableOverflow_" + fieldIndex).hide();
|
||||||
|
|
||||||
|
// insert data
|
||||||
|
for(var i = 0; i < data['data'].length; i++) {
|
||||||
|
$("#resultTable_" + fieldIndex).append("<tr></tr>");
|
||||||
|
for(var j = 0; j < data['data'][i].length; j++) {
|
||||||
|
$("#resultTable_" + fieldIndex + " tr:last-child").append("<td></td>");
|
||||||
|
$("#resultTable_" + fieldIndex + " tr:last-child td:last-child").text(data['data'][i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
|
@ -38,7 +38,7 @@
|
||||||
{% for innerItem in item.data %}
|
{% for innerItem in item.data %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><input type="checkbox" value="1"></input></td>
|
<td><input type="checkbox" value="1"></input></td>
|
||||||
<td>{{ innerItem[0]|e }}</td>
|
<td queryName="{{ innerItem[0]|e }}">{{ innerItem[0]|e }}</td>
|
||||||
<td><input type="text"></input></td>
|
<td><input type="text"></input></td>
|
||||||
<td>{{ innerItem[1]|e }}</td>
|
<td>{{ innerItem[1]|e }}</td>
|
||||||
<td>{{ innerItem[2]|e }}</td>
|
<td>{{ innerItem[2]|e }}</td>
|
||||||
|
@ -48,8 +48,14 @@
|
||||||
|
|
||||||
<button style="padding: 5px;" onclick="doQuery({{ loop.index }}, "{{ item.queryKey }}");">Query</button>
|
<button style="padding: 5px;" onclick="doQuery({{ loop.index }}, "{{ item.queryKey }}");">Query</button>
|
||||||
<p>Query result:</p>
|
<p>Query result:</p>
|
||||||
|
<p id="resultTableOverflow_{{ loop.index }}" style="color: red; display: none;">The count of query result is more than 100 items(Only the first 100 items will be shown). Please give more limitation.</p>
|
||||||
|
|
||||||
<table class="envOutput" cellspacing="0" cellpadding="5" style="margin: 10px;">
|
<table id="resultTable_{{ loop.index }}" class="envOutput" cellspacing="0" cellpadding="5" style="margin: 10px;">
|
||||||
|
<tr>
|
||||||
|
{% for innerItem in item.data %}
|
||||||
|
<td>{{ innerItem[0]|e }}</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user