aboutsummaryrefslogtreecommitdiffstats
path: root/infrastructure
diff options
context:
space:
mode:
Diffstat (limited to 'infrastructure')
-rw-r--r--infrastructure/framework-src/modules/execution.js5
-rw-r--r--infrastructure/framework-src/modules/sqlbase/sqlobj.js50
2 files changed, 52 insertions, 3 deletions
diff --git a/infrastructure/framework-src/modules/execution.js b/infrastructure/framework-src/modules/execution.js
index 1cec418..2f9d933 100644
--- a/infrastructure/framework-src/modules/execution.js
+++ b/infrastructure/framework-src/modules/execution.js
@@ -44,8 +44,11 @@ function fancyAssEval(initCode, mainCode) {
1);
}
var runner = Packages.net.appjet.oui.ScopeReuseManager.getEmpty(scalaF1(init));
+ var requestWrapper = null;
+ if (request.underlying !== undefined)
+ requestWrapper = new Packages.net.appjet.oui.RequestWrapper(request.underlying);
var ec = new Packages.net.appjet.oui.ExecutionContext(
- new Packages.net.appjet.oui.RequestWrapper(request.underlying),
+ requestWrapper,
null, runner);
return Packages.net.appjet.oui.ExecutionContextUtils.withContext(ec,
scalaF0(function() {
diff --git a/infrastructure/framework-src/modules/sqlbase/sqlobj.js b/infrastructure/framework-src/modules/sqlbase/sqlobj.js
index 4bc1263..e599c92 100644
--- a/infrastructure/framework-src/modules/sqlbase/sqlobj.js
+++ b/infrastructure/framework-src/modules/sqlbase/sqlobj.js
@@ -17,6 +17,7 @@
import("cache_utils.syncedWithCache");
import("sqlbase.sqlcommon.*");
import("jsutils.*");
+import("etherpad.log");
jimport("java.lang.System.out.println");
jimport("java.sql.Statement");
@@ -112,10 +113,13 @@ function _getJsValFromResultSet(rs, type, colName) {
} else {
r = null;
}
- } else if (type == java.sql.Types.INTEGER ||
+ } else if (type == java.sql.Types.BIGINT ||
+ type == java.sql.Types.INTEGER ||
type == java.sql.Types.SMALLINT ||
type == java.sql.Types.TINYINT) {
r = rs.getInt(colName);
+ } else if (type == java.sql.Types.DECIMAL) {
+ r = rs.getFloat(colName);
} else if (type == java.sql.Types.BIT) {
r = rs.getBoolean(colName);
} else {
@@ -192,8 +196,9 @@ function _resultRowToJsObj(resultSet) {
var metaData = resultSet.getMetaData();
var colCount = metaData.getColumnCount();
+
for (var i = 1; i <= colCount; i++) {
- var colName = metaData.getColumnName(i);
+ var colName = metaData.getColumnLabel(i);
var type = metaData.getColumnType(i);
resultObj[colName] = _getJsValFromResultSet(resultSet, type, colName);
}
@@ -338,6 +343,47 @@ function selectMulti(tableName, constraints, options) {
});
}
+function executeRaw(stmnt, params) {
+ return withConnection(function(conn) {
+ var pstmnt = conn.prepareStatement(stmnt);
+ return closing(pstmnt, function() {
+ for (var i = 0; i < params.length; i++) {
+ var v = params[i];
+
+ if (v === undefined) {
+ throw Error("value is undefined for key "+i);
+ }
+
+ if (typeof(v) == 'object' && v.isnull) {
+ pstmnt.setNull(i+1, v.type);
+ } else if (typeof(v) == 'string') {
+ pstmnt.setString(i+1, v);
+ } else if (typeof(v) == 'number') {
+ pstmnt.setInt(i+1, v);
+ } else if (typeof(v) == 'boolean') {
+ pstmnt.setBoolean(i+1, v);
+ } else if (v.valueOf && v.getDate && v.getHours) {
+ pstmnt.setTimestamp(i+1, new java.sql.Timestamp(+v));
+ } else {
+ throw Error("Cannot insert this type of javascript object: "+typeof(v)+" (key="+i+", value = "+v+")");
+ }
+ }
+
+ _qdebug(stmnt);
+ var resultSet = pstmnt.executeQuery();
+ var resultArray = [];
+
+ return closing(resultSet, function() {
+ while (resultSet.next()) {
+ resultArray.push(_resultRowToJsObj(resultSet));
+ }
+
+ return resultArray;
+ });
+ });
+ });
+}
+
/* returns number of rows updated */
function update(tableName, constraints, obj) {
var objKeys = keys(obj);