Skip to content

Instantly share code, notes, and snippets.

@Dither
Created November 14, 2016 16:45
Show Gist options
  • Save Dither/e357105763c96c22b918606f6ca530e4 to your computer and use it in GitHub Desktop.
Save Dither/e357105763c96c22b918606f6ca530e4 to your computer and use it in GitHub Desktop.
Fix for long alerts going off-screen and incorrect string parsing of SQLite Manager
From ab3b625c6a89cb8c4348a228d778d0877425389c Mon Sep 17 00:00:00 2001
From: Dither <[email protected]>
Date: Mon, 14 Nov 2016 19:40:58 +0300
Subject: [PATCH] Fix for long alerts going off-screen and incorrect string parsing
---
sqlite-manager/chrome/content/createManager.js | 2 +-
sqlite-manager/chrome/content/exim.js | 6 +--
sqlite-manager/chrome/content/treeDataTable.js | 2 +-
sqlite-manager/chrome/resource/sqlite.js | 53 ++++++++++++++------------
4 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/sqlite-manager/chrome/content/createManager.js b/sqlite-manager/chrome/content/createManager.js
index 35afaf2..fde2de0 100755
--- a/sqlite-manager/chrome/content/createManager.js
+++ b/sqlite-manager/chrome/content/createManager.js
@@ -314,7 +314,7 @@ var CreateManager = {
if (si.hasAttribute('sm_check')) {
col["type"] = si.getAttribute('sm_type');
col["check"] = si.getAttribute('sm_check');
- col["check"] = col["check"].replace("zzzz", colname, "g");
+ col["check"] = col["check"].replace(/zzzz/g, colname);
}
}
col["pk"] = $$("primarykey-" + i).checked;
diff --git a/sqlite-manager/chrome/content/exim.js b/sqlite-manager/chrome/content/exim.js
index d1d9f7a..a901603 100755
--- a/sqlite-manager/chrome/content/exim.js
+++ b/sqlite-manager/chrome/content/exim.js
@@ -220,7 +220,7 @@ var SmExim = {
var i = 0;
for(var i in columns) {
if (cEncloser == "din" || cEncloser == '"') {
- columns[i][0] = columns[i][0].replace("\"", "\"\"", "g");
+ columns[i][0] = columns[i][0].replace(/"/g,"\"\"");
data.push('"' + columns[i][0] + '"');
}
else
@@ -246,7 +246,7 @@ var SmExim = {
}
if (cEncloser == "din") {
if (typeof row[iCol] == "string") {
- row[iCol] = row[iCol].replace("\"", "\"\"", "g");
+ row[iCol] = row[iCol].replace(/"/g,"\"\"");
row[iCol] = '"' + row[iCol] + '"';
}
data.push(row[iCol]);
@@ -254,7 +254,7 @@ var SmExim = {
}
if (cEncloser == '"') {
if (typeof row[iCol] == "string") {
- row[iCol] = row[iCol].replace("\"", "\"\"", "g");
+ row[iCol] = row[iCol].replace(/"/g,"\"\"");
}
row[iCol] = '"' + row[iCol] + '"';
data.push(row[iCol]);
diff --git a/sqlite-manager/chrome/content/treeDataTable.js b/sqlite-manager/chrome/content/treeDataTable.js
index bdd1090..50550aa 100755
--- a/sqlite-manager/chrome/content/treeDataTable.js
+++ b/sqlite-manager/chrome/content/treeDataTable.js
@@ -256,7 +256,7 @@ TreeDataTable.prototype = {
}
else {
if (typeof txt == "string")
- txt = txt.replace("\"", "\"\"", "g");
+ txt = txt.replace(/"/g,"\"\"");
txt = '"' + txt + '"';
}
result.push(txt);
diff --git a/sqlite-manager/chrome/resource/sqlite.js b/sqlite-manager/chrome/resource/sqlite.js
index d6ff5d4..6c8235d 100755
--- a/sqlite-manager/chrome/resource/sqlite.js
+++ b/sqlite-manager/chrome/resource/sqlite.js
@@ -341,7 +341,7 @@ SQLiteHandler.prototype = {
this.alert("PRAGMA " + sSetting + ": exception - " + e.message);
}
},
-
+
tableExists: function(sTable, sDbName) {
if (typeof sDbName == "undefined")
return this.dbConn.tableExists(sTable);
@@ -362,7 +362,7 @@ SQLiteHandler.prototype = {
return false;
},
- //getObjectList: must return an array of names of type=argument
+ //getObjectList: must return an array of names of type=argument
// Type = master|table|index|view|trigger,
//empty array if no object found
getObjectList: function(sType, sDb) {
@@ -375,7 +375,7 @@ SQLiteHandler.prototype = {
aResult = ["sqlite_master"];
if (sDb == "temp")
aResult = ["sqlite_temp_master"];
- return aResult;
+ return aResult;
}
var sTable = this.getPrefixedMasterName(sDb);
@@ -410,9 +410,9 @@ SQLiteHandler.prototype = {
var extracol = "";
var iRetVal = 0;
var sLimitClause = " LIMIT " + iLimit + " OFFSET " + iOffset;
-
+
if (sObjType == "table" || sObjType == "master") {
- //find whether the rowid is needed
+ //find whether the rowid is needed
//or the table has an integer primary key
var rowidcol = this.getTableRowidCol(sObjName);
if (rowidcol["name"] == "rowid") {
@@ -462,7 +462,7 @@ SQLiteHandler.prototype = {
}
return oRow;
},
-
+
emptyTable: function(sTableName) {
var sQuery = "DELETE FROM " + this.getPrefixedName(sTableName, "");
return this.confirmAndExecute([sQuery], "Delete All Records");
@@ -590,9 +590,9 @@ SQLiteHandler.prototype = {
var aQueries = [];
aQueries.push("ALTER TABLE " + sTab + " RENAME TO " + sTempTableName);
- aQueries.push("CREATE TABLE " + sTab + " (" + coldef + ")");
+ aQueries.push("CREATE TABLE " + sTab + " (" + coldef + ")");
aQueries.push("INSERT INTO " + sTab + " SELECT " + colList + " FROM " + sTempTable);
- aQueries.push("DROP TABLE " + sTempTable);
+ aQueries.push("DROP TABLE " + sTempTable);
var bReturn = this.confirmAndExecute(aQueries, sInfo, "confirm.otherSql");
return bReturn;
@@ -603,9 +603,9 @@ SQLiteHandler.prototype = {
this.aTableData = new Array();
this.aTableType = new Array();
// if aColumns is not null, there is a problem in tree display
- this.aColumns = null;
+ this.aColumns = null;
var bResult = false;
-
+
var timeStart = Date.now();
try { // mozIStorageStatement
var stmt = this.dbConn.createStatement(sQuery);
@@ -618,7 +618,7 @@ SQLiteHandler.prototype = {
this.setErrorString();
return false;
}
-
+
var iCols = 0;
var iType, colName;
try {
@@ -629,7 +629,7 @@ SQLiteHandler.prototype = {
for (var i = 0; i < iCols; i++) {
colName = stmt.getColumnName(i);
aTemp = [colName, iType];
- this.aColumns.push(aTemp);
+ this.aColumns.push(aTemp);
}
} catch (e) {
stmt.finalize();
@@ -652,7 +652,7 @@ SQLiteHandler.prototype = {
this.aColumns[i][1] = iType;
}
switch (iType) {
- case stmt.VALUE_TYPE_NULL:
+ case stmt.VALUE_TYPE_NULL:
cell = null;
break;
case stmt.VALUE_TYPE_INTEGER:
@@ -687,7 +687,7 @@ SQLiteHandler.prototype = {
}
}
break;
- default: sData = "<unknown>";
+ default: sData = "<unknown>";
}
aTemp.push(cell);
aType.push(iType);
@@ -744,7 +744,7 @@ SQLiteHandler.prototype = {
this.setErrorString();
return false;
}
-
+
if (stmt.columnCount != 1)
return false;
@@ -794,7 +794,7 @@ SQLiteHandler.prototype = {
}
if (iNumPk == 1 && iIntPk == 1)
return aReturn;
-
+
aReturn["name"] = "rowid";
aReturn["cid"] = 0;
return aReturn;
@@ -818,10 +818,10 @@ SQLiteHandler.prototype = {
if(aList[i].name == sIndexName)
aReturn.unique = aList[i].unique;
}
-
+
return aReturn;
},
-
+
select : function(file,sql,param) {
var ourTransaction = false;
if (this.dbConn.transactionInProgress) {
@@ -831,7 +831,7 @@ SQLiteHandler.prototype = {
var statement = this.dbConn.createStatement(sql);
//Cu.reportError("createStatement");
if (param) {
- for (var m = 2, arg = null; arg = arguments[m]; m++)
+ for (var m = 2, arg = null; arg = arguments[m]; m++)
statement.bindUTF8StringParameter(m-2, arg);
}
try {
@@ -881,7 +881,7 @@ SQLiteHandler.prototype = {
this.miTime = Date.now() - timeStart;
return true;
- },
+ },
executeTransaction: function(aQueries) {
//IS THIS NEEDED?
@@ -923,7 +923,7 @@ SQLiteHandler.prototype = {
this.miTime = Date.now() - timeStart;
return true;
- },
+ },
// executeWithParams : execute a query with parameter binding
executeWithParams: function(sQuery, aParamData) {
@@ -1071,6 +1071,11 @@ SQLiteHandler.prototype = {
},
onSqlError: function(ex, msg, SQLmsg, bAlert) {
+ var startOfMessage
+ if (msg.search(/(.*\n){10,}/) > -1) {
+ // msg is more than 10 lines long
+ msg = /(.*\n?){1,10}/.exec(msg)[0] + '...';
+ }
msg = "SQLiteManager: " + msg;
if (SQLmsg != null)
msg += " [ " + SQLmsg + " ]";
@@ -1406,7 +1411,7 @@ var SQLiteFn = {
quote: function(str) {
if (typeof str == "string")
- str = str.replace("'", "''", "g");
+ str = str.replace(/'/g,"''");
return "'" + str + "'";
},
@@ -1539,12 +1544,12 @@ function getCsvRowFromArray(arrRow, arrTypes, oCsv) {
case SQLiteTypes.REAL:
case SQLiteTypes.BLOB:
break;
- case SQLiteTypes.NULL:
+ case SQLiteTypes.NULL:
arrRow[i] = "";
break;
case SQLiteTypes.TEXT:
default:
- arrRow[i] = arrRow[i].replace("\"", "\"\"", "g");
+ arrRow[i] = arrRow[i].replace(/"/g,"\"\"");
arrRow[i] = '"' + arrRow[i] + '"';
break;
}
--
2.8.3.windows.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment