diff options
author | Egil Moeller <egil.moller@freecode.no> | 2010-03-12 21:13:39 +0100 |
---|---|---|
committer | Egil Moeller <egil.moller@freecode.no> | 2010-03-12 21:13:39 +0100 |
commit | 16b37f7a1f9ff8e559e90261c8f6cd3da46dae49 (patch) | |
tree | ef0d0e9f4e9e0186d3ddb922818e949afcf9e1b4 /trunk/infrastructure/framework-src/modules/sqlbase/sqlobj.js | |
parent | 648f6a226b076424e9df533107a5c0cf1804293a (diff) | |
download | etherpad-16b37f7a1f9ff8e559e90261c8f6cd3da46dae49.tar.gz etherpad-16b37f7a1f9ff8e559e90261c8f6cd3da46dae49.tar.xz etherpad-16b37f7a1f9ff8e559e90261c8f6cd3da46dae49.zip |
Tag search works fully but looks awfull
Diffstat (limited to 'trunk/infrastructure/framework-src/modules/sqlbase/sqlobj.js')
-rw-r--r-- | trunk/infrastructure/framework-src/modules/sqlbase/sqlobj.js | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/trunk/infrastructure/framework-src/modules/sqlbase/sqlobj.js b/trunk/infrastructure/framework-src/modules/sqlbase/sqlobj.js index 4bc1263..e599c92 100644 --- a/trunk/infrastructure/framework-src/modules/sqlbase/sqlobj.js +++ b/trunk/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); |