How to use booleanFalseValue method in Best

Best JavaScript code snippet using best

oracle_db.js

Source:oracle_db.js Github

copy

Full Screen

1var path = Npm.require('path');2var Fiber = Npm.require('fibers');3var Future = Npm.require(path.join('fibers', 'future'));4OracleDB = function (connection) {5 var self = this;6 7 self.connection = connection;8 self.db = NpmModuleOracledb;9 self.db.maxRows = 1000;10 self.db.prefetchRows = 100;11 self.db.autoCommit = true;12 self._tables = {};13};14OracleDB._databases = {};15OracleDB.getDatabase = function(connection) {16 var key = connection.user+"@"+connection.connectString;17 var db = OracleDB._databases[key];18 19 if(!db) {20 var user = OracleDB.executeCommand(connection, "select * from user_users", [], {});21 22 db = new OracleDB(connection);23 db.user = user;24 db.databaseName = key;25 OracleDB._databases[key] = db;26 }27 return db;28};29OracleDB.q = function(name) {30 return '"'+name+'"';31};32OracleDB.uq = function(name) {33 return name.substr(1, name.length-2);34};35// Meteor -> Oracle36OracleDB._tableNameM2O = function(name) {37 return name;38};39OracleDB._columnNameM2O = function(name) {40 return name;41};42//Oracle -> Meteor43OracleDB._tableNameO2M = function(name) {44 return name;45};46OracleDB._columnNameO2M = function(name) {47 return name;48};49OracleDB._processResult = function(sqlOptions, result) {50 var md = result.metaData;51 var rows = result.rows;52 var records = [];53 var nameMap = {};54 if(md && rows) {55 for (var i = 0; i < rows.length; i++) {56 var row = rows[i];57 var rec = {};58 for(var j = 0; j < md.length; j++) {59 var mdrec = md[j];60 var val = row[j];61 62 // Turn null into undefined so $exist work properly in minimongo63 if(val === null) {64 continue;65 }66 67 if(sqlOptions.booleanTrueValue !== undefined) {68 if(val === sqlOptions.booleanTrueValue) {69 val = true;70 } else if(val === sqlOptions.booleanFalseValue) {71 val = false;72 }73 }74 var name = mdrec['name'];75 76 var name2 = nameMap[name];77 if(!name2) {78 var name2 = OracleDB._columnNameO2M(name);79 nameMap[name] = name2;80 }81 rec[name2] = val;82 }83 records.push(rec);84 }85 86 result.records = records;87 delete result.rows;88 }89 return result;90}91OracleDB.executeCommand = function(connection, sql, sqlParameters, sqlOptions) {92 sqlParameters = sqlParameters || {};93 sqlOptions = sqlOptions || {};94 95 var future = new Future;96 var onComplete = future.resolver();97 try98 {99 NpmModuleOracledb.getConnection(100 connection,101 Meteor.bindEnvironment(102 103 function (err, db) {104 if (err) {105 onComplete(err);106 return;107 }108 109 if(sqlOptions.sqlDebug) {110 if(sql.indexOf("SELECT * FROM \"oplog\"") < 0) {111 console.log(sql, sqlParameters);112 }113 }114 115 db.execute(116 sql,117 sqlParameters,118 sqlOptions,119 function(err, result) {120 121 db.release(122 function(err2) {123 if (err2) {124 console.error(err2.message);125 onComplete(err2, result);126 } else {127 onComplete(err, result);128 }129 }); 130 }131 );132 },133 onComplete // onException134 )135 );136 }137 catch(ex)138 {139 console.error("ERROR in SQL preparation: "+sql);140 throw ex;141 }142 try143 {144 var result = future.wait();145 result = OracleDB._processResult(sqlOptions, result);146 return result;147 }148 catch(ex)149 {150 console.error("ERROR in SQL: ", sql);151 console.error("ERROR MESSAGE: ", ex.message);152 throw ex;153 }154};155OracleDB.prototype.executeCommand = function(sql, sqlParameters, sqlOptions) {156 var self = this;157 158 return OracleDB.executeCommand(self.connection, sql, sqlParameters, sqlOptions);159};160OracleDB.executeBatch = function(connection, batch, sqlOptions) {161 sqlOptions = sqlOptions || {};162 163 var future = new Future;164 var onComplete = future.resolver();165 try166 {167 NpmModuleOracledb.getConnection(168 connection,169 Meteor.bindEnvironment(170 171 function (err, db) {172 if (err) {173 onComplete(err);174 return;175 }176 177 var results = [];178 179 try180 {181 // For each SQL in the batch182 for(var bi = 0; bi < batch.length; bi++) {183 var bv = batch[bi];184 185 if(sqlOptions.sqlDebug) {186 console.log("BATCH ITEM["+bi+"]", bv.sql, bv.sqlParameters);187 }188 189 var future2 = new Future;190 var onComplete2 = future2.resolver();191 192 db.execute(193 bv.sql,194 bv.sqlParameters,195 {autoCommit: false},196 function(err, result) {197 if(err) {198 console.log("BATCH ["+bi+"] EXECUTED WITH ERROR: ", err.message, bv);199 }200 onComplete2(err, result);201 }202 );203 var result = future2.wait();204 results.push(result);205 }206 var commitFuture = new Future;207 var onCommitComplete = commitFuture.resolver();208 db.commit(function(err2){209 if (err2) {210 console.error("BATCH COMMIT FAILED: ", err2.message);211 err = err || err2;212 }213 214 onCommitComplete(err2, null);215 });216 217 commitFuture.wait();218 }219 catch(e) {220 err = err || e;221 var rollbackFuture = new Future;222 var onRollbackComplete = rollbackFuture.resolver();223 db.rollback(function(err2){224 if (err2) {225 console.error("BATCH ROLLBACK FAILED: ", err2.message);226 err = err || err2;227 }228 229 onRollbackComplete(err2, null);230 });231 232 rollbackFuture.wait();233 }234 finally {235 db.release(236 function(err2) {237 if (err2) {238 console.error("BATCH CONNECTION RELEASE ERROR:", err.message);239 err = err || err2;240 }241 242 // Big return!!!243 onComplete(err, results);244 });245 }246 },247 onComplete // onException248 )249 );250 }251 catch(ex)252 {253 console.error("ERROR in SQL BATCH preparation: "+batch);254 throw ex;255 }256 try257 {258 var result = future.wait();259 260 for(var i = 0; i < result.length; i++) {261 result[i] = OracleDB._processResult(sqlOptions, result[i]);262 }263 264 return result;265 }266 catch(ex)267 {268 console.error("ERROR in SQL BATCH: "+ex.message);269 throw ex;270 }271};272OracleDB.prototype.executeBatch = function(batch, sqlOptions) {273 var self = this;274 275 return OracleDB.executeBatch(self.connection, batch, sqlOptions);276};277OracleDB.prototype._getJsonColumns = function(sqlTable, op, oracleOptions, o) {278 var self = this;279 var tableResult = self._tables[sqlTable];280 var columns = tableResult["columns"];281 var s = "";282 var nested = sqlTable.indexOf("$") >= 0;283 284 var i = 0;285 var nw = ":NEW";286 if(op === 'w' || op === 'd') {287 nw = ":OLD";288 }289 290 for(var c in columns) {291 var cv = columns[c];292 293 if(op === 'u' && c === "_id") continue; // exclude for updates294 if(op === 'w' || op === 'd') {295 if(!(c === "_id" || c === "_value")) {296 continue;297 }298 }299 if (i > 0) {300 s = s + "\n";301 }302 s = s + "\t\t";303 304 if(op === 'u') {305 s = s + 'IF ('+nw+'."'+c+'" <> :OLD."'+c+'" OR ('+nw+'."'+c+'" IS NOT NULL AND :OLD."'+c+'" IS NULL) OR ('+nw+'."'+c+'" IS NULL AND :OLD."'+c+'" IS NOT NULL)) THEN ';306 s = s + "IF "+o+" is not null THEN "+o+" := "+o+" || ', '; END IF; ";307 } else {308 if(i > 0) {309 s = s + o+" := "+o+" || ', ';\n\t\t";310 }311 }312 313 s = s + o+" := "+o+" || ";314 if(cv.isBoolean) {315 s = s + '\'"'+c+'": \'||nvl('+nw+'."'+c+'", \'null\')';316 } else if(cv.dataType === 'VARCHAR2') {317 s = s + '\'"'+c+'": "\'||replace(replace('+nw+'."'+c+'", chr(10), \'\\n\'), \'"\', \'\\"\')||\'"\'';318 } else if(cv.dataType === 'NUMBER') {319 s = s + '\'"'+c+'": \'||nvl(meteor_pkg.js_number('+nw+'."'+c+'"), \'null\')'; 320 } else if(cv.dataType === 'DATE') {321 s = s + '\'"'+c+'": {"$date": "\'||to_char('+nw+'."'+c+'", \'yyyy-mm-dd"T"hh24:mi:ss".000Z"\')||\'"}\''; 322 } else if(cv.dataType === 'TIMESTAMP') {323 s = s + '\'"'+c+'": {"$date": "\'||to_char('+nw+'."'+c+'", \'yyyy-mm-dd"T"hh24:mi:ss.ff3"Z"\')||\'"}\''; 324 }325 326 if(op === 'u') {327 s = s + '; END IF';328 }329 s = s + ';';330 i++;331 }332 333 return i === 0 ? null : s;334};335OracleDB.prototype._refreshTable = function(sqlTable, oracleOptions) {336 var self = this;337 var tableResult = self._tables[sqlTable];338 339 if(!tableResult) {340 var tableSql = 'select table_name as "tableName", status, num_rows as "numRows" from user_tables where table_name = :1';341 var tableResult = self.executeCommand(tableSql, [sqlTable])342 343 if(!tableResult.records || tableResult.records.length === 0) {344 // Table does not exist in the database345 return;346 }347 348 self._tables[sqlTable] = tableResult;349 }350 351 var colSql = 'select column_name as "columnName", column_id as "columnId", data_type as "dataType", data_length as "dataLength", data_precision as "dataPrecision", data_scale as "dataScale", nullable as "nullable", default_length as "defaultLength" from user_tab_columns where table_name = :1 order by column_id';352 var colResult = self.executeCommand(colSql, [sqlTable], oracleOptions)353 var columns = {};354 var ccn = {};355 for(var i = 0; i < colResult.records.length; i++) {356 var rec = colResult.records[i];357 var oraColumn = rec.columnName;358 var meteorColumn = OracleDB._columnNameO2M(oraColumn);359 columns[oraColumn] = rec;360 rec["meteorName"] = meteorColumn;361 ccn[meteorColumn] = oraColumn;362 }363 tableResult["colRecords"] = colResult.records;364 tableResult["columns"] = columns;365 tableResult["ccn"] = ccn;366 367 var consSql = 'select constraint_name as "constraintName", constraint_type as "constraintType" from user_constraints where table_name = :1 and status = \'ENABLED\' and invalid is null';368 var consResult = self.executeCommand(consSql, [sqlTable], oracleOptions)369 var constraints = {};370 for(var i = 0; i < consResult.records.length; i++) {371 var rec = consResult.records[i];372 var s = sqlTable+'_BOOL_CHK';373 if(rec.constraintName.substr(0, s.length) == s) {374 // It's boolean check!375 var index = rec.constraintName.substr(s.length);376 tableResult.colRecords[index-1]["isBoolean"] = true;377 }378 s = sqlTable+"_NULL_CHK";379 if(rec.constraintName.substr(0, s.length) == s) {380 // It's null check!381 var index = rec.constraintName.substr(s.length);382 tableResult.colRecords[index-1]["isNull"] = true;383 }384 }385 tableResult["consRecords"] = consResult.records;386 387 var indSql = 'select index_name as "indexName", index_type as "indexType", uniqueness as "uniqueness", status as "status", compression as "compression" from user_indexes where table_name = :1';388 var indResult = self.executeCommand(indSql, [sqlTable], oracleOptions)389 var indexes = {};390 for(var i = 0; i < indResult.records.length; i++) {391 var rec = indResult.records[i];392 indexes[rec.indexName] = rec;393 }394 tableResult["indexes"] = indexes;395 // tableResult["indResult"] = indResult;396 397 var detSql = 398 'select table_name as "tableName", substr(table_name, length(:0)+2) as "fieldName" from user_constraints '+399 "where table_name like :1||'$%' and constraint_type='R' " +400 "and r_constraint_name in " +401 "(select constraint_name from user_constraints where constraint_type in ('P','U') and table_name=:2) ";402 var detResult = self.executeCommand(detSql, [sqlTable, sqlTable, sqlTable], oracleOptions)403 var details = {};404 for(var key in detResult.records) {405 var rec = detResult.records[key];406 details[OracleDB._columnNameO2M(rec.fieldName)] = {tableName: OracleDB._tableNameO2M(rec.tableName), fieldName: OracleDB._columnNameO2M(rec.fieldName)};407 }408 tableResult["details"] = details;409 for(var di in details) {410 self._ensureTable(details[di].tableName, oracleOptions, sqlTable);411 }412 413 var nested = sqlTable.indexOf("$") >= 0;414 415 // Create or Replace the Trigger416 if(sqlTable !== 'oplog') {417 var trgSql = 'create or replace trigger "'+sqlTable+'_trg"\n';418 trgSql = trgSql + "after insert or update or delete\n"; 419 trgSql = trgSql + 'on "' + sqlTable + '"\n';420 trgSql = trgSql + "for each row\n";421 trgSql = trgSql + "declare\n";422 trgSql = trgSql + "\top varchar2(1);\n";423 trgSql = trgSql + "\tns varchar2(200);\n";424 trgSql = trgSql + "\to varchar2(4000);\n";425 trgSql = trgSql + "\to2 varchar2(4000);\n";426 trgSql = trgSql + "begin\n";427 trgSql = trgSql + "\tIF INSERTING THEN\n";428 trgSql = trgSql + "\t\top := 'i';\n";429 trgSql = trgSql + "\t\tns := 'meteor@localhost/XE'||'.'||'"+sqlTable+"';\n";430 trgSql = trgSql + "\t\to := '';\n";431 trgSql = trgSql + self._getJsonColumns(sqlTable, 'i', oracleOptions, "o") + "\n";432 trgSql = trgSql + "\t\to := '{'||o||'}';\n";433 trgSql = trgSql + "\t\to2 := null;\n";434 trgSql = trgSql + '\t\tinsert into "oplog" ("id", "ts", "scn", "tr", "v", "op", "ns", "o", "o2")\n'435 trgSql = trgSql + '\t\tvalues ("oplog_seq".nextval, current_timestamp, dbms_flashback.get_system_change_number, dbms_transaction.local_transaction_id, 2, op, ns, o, o2);\n'; 436 trgSql = trgSql + "\tELSIF UPDATING THEN\n";437 trgSql = trgSql + "\t\top := 'u';\n";438 trgSql = trgSql + "\t\tns := 'meteor@localhost/XE'||'.'||'"+sqlTable+"';\n";439 var cl = self._getJsonColumns(sqlTable, 'u', oracleOptions, "o");440 if(cl) {441 trgSql = trgSql + "\t\to := '';\n"442 trgSql = trgSql + cl + "\n";443 trgSql = trgSql + "\t\tIF o is not null THEN\n"; 444 trgSql = trgSql + "\t\t\to := '{\"$set\": {'||o||'}}';\n";445 trgSql = trgSql + "\t\to2 := '';\n";446 trgSql = trgSql + self._getJsonColumns(sqlTable, 'w', oracleOptions, "o2") + "\n";447 trgSql = trgSql + "\t\to2 := '{'||o2||'}';\n";448 trgSql = trgSql + '\t\t\tinsert into "oplog" ("id", "ts", "scn", "tr", "v", "op", "ns", "o", "o2")\n';449 trgSql = trgSql + '\t\t\tvalues ("oplog_seq".nextval, current_timestamp, dbms_flashback.get_system_change_number, dbms_transaction.local_transaction_id, 2, op, ns, o, o2);\n';450 trgSql = trgSql + "\t\tEND IF;\n";451 }452 trgSql = trgSql + "\tELSIF DELETING THEN\n";453 trgSql = trgSql + "\t\top := 'd';\n";454 trgSql = trgSql + "\t\tns := 'meteor@localhost/XE'||'.'||'"+sqlTable+"';\n";455 trgSql = trgSql + "\t\to := '';\n";456 trgSql = trgSql + self._getJsonColumns(sqlTable, 'w', oracleOptions, "o") + "\n";457 trgSql = trgSql + "\t\to := '{'||o||'}';\n";458 trgSql = trgSql + "\t\to2 := null;\n"; 459 trgSql = trgSql + '\t\tinsert into "oplog" ("id", "ts", "scn", "tr", "v", "op", "ns", "o", "o2")\n';460 trgSql = trgSql + '\t\tvalues ("oplog_seq".nextval, current_timestamp, dbms_flashback.get_system_change_number, dbms_transaction.local_transaction_id, 2, op, ns, o, o2);\n';461 trgSql = trgSql + "\tEND IF;\n";462 trgSql = trgSql + " end;\n";463 var trgResult = self.executeCommand(trgSql, [], oracleOptions)464 }465};466OracleDB.prototype._ensureTable = function(sqlTable, oracleOptions, parentSqlTable) {467 var self = this;468 469 if(!self._tables[sqlTable]) {470 self._refreshTable(sqlTable, oracleOptions);471 472 if(!self._tables[sqlTable]) {473 // Table doesn't exist, we should create it474 var sql;475 var result;476 477 if(parentSqlTable) {478 sql = "create table "+OracleDB.q(sqlTable)+" ("+OracleDB.q("_id")+" varchar2(17) not null, "+OracleDB.q("_indexNo")+" number(20, 0) not null)";479 } else {480 sql = "create table "+OracleDB.q(sqlTable)+" ("+OracleDB.q("_id")+" varchar2(17) not null)"; 481 }482 if(oracleOptions.sqlDebug) {483 console.log(sql);484 };485 486 result = self.executeCommand(sql, []);487 // Add a primary key488 if(parentSqlTable) {489 sql = "alter table "+OracleDB.q(sqlTable)+" add constraint "+OracleDB.q(sqlTable+"_PK")+" primary key ("+OracleDB.q("_id")+", "+OracleDB.q("_indexNo")+")";490 } else {491 sql = "alter table "+OracleDB.q(sqlTable)+" add constraint "+OracleDB.q(sqlTable+"_PK")+" primary key ("+OracleDB.q("_id")+")";492 }493 if(oracleOptions.sqlDebug) {494 console.log(sql);495 };496 result = self.executeCommand(sql, []); 497 // Add a foreign key498 if(parentSqlTable) {499 sql = "alter table "+OracleDB.q(sqlTable)+" add constraint "+OracleDB.q(sqlTable+"_FK")+" foreign key ("+OracleDB.q("_id")+") references "+OracleDB.q(parentSqlTable)+"("+OracleDB.q("_id")+") on delete cascade";500 if(oracleOptions.sqlDebug) {501 console.log(sql);502 };503 result = self.executeCommand(sql, []);504 }505 506 // Verify, that the table has been created507 self._refreshTable(sqlTable, oracleOptions);508 if(!self._tables[sqlTable]) {509 throw new Error("Table creation failed");510 }511 }512 513 if(parentSqlTable) {514 self._refreshTable(parentSqlTable, oracleOptions);515 }516 }517};518OracleDB.prototype._getColumnType = function(sqlTable, column, value, oracleOptions, postponedBooleanColumns, postponedNullColumns) {519 var self = this;520 521 var type = undefined;522 523 if(value === null) {524 type = "varchar2(1)";525 postponedNullColumns.push(column);526 } else if(typeof value === 'string') {527 var len = Buffer.byteLength(value, 'utf8');528 if(len <= 0) len = 1;529 type = "varchar2("+len+")";530 } else if(typeof value === 'number') {531 var ns = '' + value;532 var index = ns.indexOf(".");533 if(index >= 0) {534 // contains "."535 type = "number("+(ns.length-1)+", "+(ns.length - index - 1)+")"; 536 } else {537 type = "number("+ns.length+")"; 538 }539 } else if (typeof value === 'boolean') {540 if(typeof oracleOptions.booleanTrueValue === 'number'541 && typeof oracleOptions.booleanFalseValue === 'number') {542 type = "number";543 if(0 <= oracleOptions.booleanTrueValue && oracleOptions.booleanTrueValue < 10 &&544 0 <= oracleOptions.booleanFalseValue && oracleOptions.booleanFalseValue < 10 ) {545 type = "number(1)";546 }547 } else if(typeof oracleOptions.booleanTrueValue === 'string'548 && typeof oracleOptions.booleanFalseValue === 'string') {549 var maxLen = oracleOptions.booleanTrueValue.length;550 551 if(maxLen < oracleOptions.booleanFalseValue.length) {552 maxLen = oracleOptions.booleanFalseValue.length;553 }554 type = "varchar2("+maxLen+")"; // "true" or "false"555 } else {556 console.log("oracleOptions", oracleOptions);557 throw new Error("Invalid parameters booleanTrueValue or booleanFalseValue");558 }559 postponedBooleanColumns.push(column);560 } else if(value instanceof Date) {561 type = "date";562 } else if(value instanceof Array) {563 } else if(value !== null && typeof value === 'object') {564 }565 566 if(type) {567 if(value === null) {568 type = type + " null";569 } else {570 // Check if there are any records in the table571 var sql = "select "+OracleDB.q("_id")+" from "+OracleDB.q(sqlTable)+" where rownum = 1";572 573 var result = self.executeCommand(sql, [], oracleOptions);574 if(result.records.length === 0) {575 // No rows, turn the column not null576 type = type + " not null";577 }578 579 }580 }581 return type;582};583OracleDB.prototype._ensureColumnsPostProcess = function(sqlTable, oracleOptions, refreshCols, postponedBooleanColumns, postponedNullColumns) {584 var self = this;585 if(refreshCols) {586 self._refreshTable(sqlTable, oracleOptions);587 refreshCols = false;588 }589 var table = self._tables[sqlTable]; 590 591 for(var i = 0; i < postponedBooleanColumns.length; i++) {592 var column = postponedBooleanColumns[i];593 594 var columnDesc = table.columns[column];595 var sql = "alter table "+OracleDB.q(sqlTable)+" add constraint "+ OracleDB.q(sqlTable + "_BOOL_CHK" + columnDesc.columnId) + " CHECK ("+596 OracleDB.q(columnDesc.columnName)+" IN (NULL, '"+oracleOptions.booleanTrueValue+"', '"+oracleOptions.booleanFalseValue+"')) ENABLE";597 var result = self.executeCommand(sql, [], oracleOptions); 598 refreshCols = true;599 }600 for(var i = 0; i < postponedNullColumns.length; i++) {601 var column = postponedNullColumns[i];602 603 var columnDesc = table.columns[column];604 var sql = "alter table "+OracleDB.q(sqlTable)+" add constraint "+ OracleDB.q(sqlTable + "_NULL_CHK" + columnDesc.columnId) + " CHECK ("+605 OracleDB.q(columnDesc.columnName)+" IS NULL) ENABLE";606 var result = self.executeCommand(sql, [], oracleOptions);607 608 refreshCols = true;609 }610 if(refreshCols) {611 self._refreshTable(sqlTable, oracleOptions);612 }613};614OracleDB.prototype._ensureSelectableColumns = function(sqlTable, fields, oracleOptions) {615 var self = this;616 var table = self._tables[sqlTable];617 var postponedBooleanColumns = [];618 var postponedNullColumns = [];619 var refreshCols = false;620 621 for(var column in fields) {622 var value = fields[column];623 if(value || value === null) {624 column = OracleDB._columnNameM2O(column);625 626 var columnDesc = table.columns[column]; 627 628 if(!columnDesc) {629 var type = "varchar2(1) null";630 631 var sql = "alter table "+OracleDB.q(sqlTable)+" add ("+OracleDB.q(column)+" "+type+")";632 var result = self.executeCommand(sql, [], oracleOptions);633 634 postponedNullColumns.push(column);635 refreshCols = true;636 }637 }638 }639 640 self._ensureColumnsPostProcess(sqlTable, oracleOptions, refreshCols, postponedBooleanColumns, postponedNullColumns); 641};642OracleDB.prototype._ensureColumns = function(sqlTable, doc, oracleOptions, parentSqlTable, doXCheck) {643 var self = this;644 var table = self._tables[sqlTable];645 if(!table) {646 self._ensureTable(sqlTable, oracleOptions, parentSqlTable);647 table = self._tables[sqlTable];648 649 if(!table) {650 throw new Error("Failed to create a new table");651 }652 }653 654 var postponedBooleanColumns = [];655 var postponedNullColumns = [];656 var refreshCols = false;657 658 for(var column in doc) {659 var value = doc[column];660 var columnDesc = table.columns[column]; 661 if(!columnDesc) {662 var type = self._getColumnType(sqlTable, column, value, oracleOptions, postponedBooleanColumns, postponedNullColumns);663 664 if(type) {665 var sql = "alter table "+OracleDB.q(sqlTable)+" add ("+OracleDB.q(column)+" "+type+")";666 var result = self.executeCommand(sql, [], oracleOptions);667 refreshCols = true;668 }669 } else {670 if(value !== null && (value instanceof Date || !(value instanceof Array) && typeof value !== 'object')) {671 if(columnDesc.isNull) {672 // Drop the null constraint673 var sql = "alter table "+OracleDB.q(sqlTable)+" drop constraint "+ OracleDB.q(sqlTable + "_NULL_CHK" + columnDesc.columnId);674 var result = self.executeCommand(sql, [], oracleOptions);675 refreshCols = true;676 // Check if there are any records in the table677 sql = "select "+OracleDB.q("_id")+" from "+OracleDB.q(sqlTable)+" where rownum = 1";678 679 result = self.executeCommand(sql, [], oracleOptions);680 if(result.records.length === 0) {681 // No rows, turn the column not null682 sql = "alter table "+OracleDB.q(sqlTable)+" modify ("+OracleDB.q(column)+" not null)";683 684 result = self.executeCommand(sql, [], oracleOptions); 685 }686 } 687 }688 689 if(value === null) {690 if(columnDesc.nullable === 'N') {691 // Allow NULLs692 var sql = "alter table "+OracleDB.q(sqlTable)+" modify ("+OracleDB.q(column)+" null)";693 var result = self.executeCommand(sql, [], oracleOptions);694 refreshCols = true;695 }696 } else if(typeof value === 'string') {697 if(columnDesc.dataType === "VARCHAR2" && !columnDesc.isBoolean) {698 var len = Buffer.byteLength(value, 'utf8');699 if(len <= 0) len = 1;700 701 if(columnDesc.dataLength < len) {702 var sql = "alter table "+OracleDB.q(sqlTable)+" modify ("+OracleDB.q(column)+" varchar2("+len+"))";703 var result = self.executeCommand(sql, [], oracleOptions);704 refreshCols = true;705 }706 }707 } else if(typeof value === 'number') {708 var ns = '' + value;709 var index = ns.indexOf(".");710 var precision;711 var scale;712 if(index >= 0) {713 // contains "."714 precision = (ns.length-1);715 scale = (ns.length - index - 1); 716 } else {717 precision = ns.length;718 scale = 0; 719 }720 721 if(!columnDesc.isBoolean)722 if(columnDesc.dataType === "VARCHAR2") {723 var part1 = (precision - scale);724 var part2 = scale;725 var dbPart1 = columnDesc.dataLength;726 var dbPart2 = 0;727 var newPrecision = part1 >= dbPart1 ? part1 : dbPart1;728 var newScale = part2 >= dbPart2 ? part2 : dbPart2;729 newPrecision += newScale;730 // Always alter table731 var sql = "alter table "+OracleDB.q(sqlTable)+" modify ("+OracleDB.q(column)+" number("+newPrecision+", "+newScale+"))";732 var result = self.executeCommand(sql, [], oracleOptions);733 refreshCols = true;734 } else if(columnDesc.dataType === "NUMBER") {735 var part1 = (precision - scale);736 var part2 = scale;737 var dbPart1 = (columnDesc.dataPrecision - columnDesc.dataScale);738 var dbPart2 = columnDesc.dataScale;739 var newPrecision = part1 >= dbPart1 ? part1 : dbPart1;740 var newScale = part2 >= dbPart2 ? part2 : dbPart2;741 newPrecision += newScale;742 if(newPrecision > columnDesc.dataPrecision || newScale > columnDesc.dataScale) {743 var sql = "alter table "+OracleDB.q(sqlTable)+" modify ("+OracleDB.q(column)+" number("+newPrecision+", "+newScale+"))";744 var result = self.executeCommand(sql, [], oracleOptions);745 refreshCols = true;746 }747 }748 } else if (typeof value === 'boolean') {749 if(columnDesc.isNull) {750 var type = undefined;751 752 if(typeof oracleOptions.booleanTrueValue === 'number'753 && typeof oracleOptions.booleanFalseValue === 'number') {754 type = "number";755 if(0 <= oracleOptions.booleanTrueValue && oracleOptions.booleanTrueValue < 10 &&756 0 <= oracleOptions.booleanFalseValue && oracleOptions.booleanFalseValue < 10) {757 if(columnDesc.dataType !== "NUMBER") {758 type = "number(1)";759 }760 }761 } else if(typeof oracleOptions.booleanTrueValue === 'string'762 && typeof oracleOptions.booleanFalseValue === 'string') {763 var maxLen = oracleOptions.booleanTrueValue.length;764 765 if(maxLen < oracleOptions.booleanFalseValue.length) {766 maxLen = oracleOptions.booleanFalseValue.length;767 }768 if(columnDesc.dataType !== "VARCHAR2" || columnDesc.dataLength < maxLen) {769 type = "varchar2("+maxLen+")"; // "true" or "false"770 }771 } else {772 throw new Error("Invalid parameters booleanTrueValue or booleanFalseValue", oracleOptions);773 }774 775 if(type) {776 var sql = "alter table "+OracleDB.q(sqlTable)+" modify ("+OracleDB.q(column)+" "+type+")";777 var result = self.executeCommand(sql, [], oracleOptions);778 }779 postponedBooleanColumns.push(column);780 }781 } else if(value instanceof Date) {782 if(columnDesc.isNull) {783 var type = "date";784 785 var sql = "alter table "+OracleDB.q(sqlTable)+" modify ("+OracleDB.q(column)+" "+type+")";786 var result = self.executeCommand(sql, [], oracleOptions); 787 }788 } else if(value instanceof Array) {789 continue;790 } else if(value != null && typeof value === 'object') {791 continue; 792 }793 }794 }795 796 // Crosscheck is any columns are missing in the document797 if(doXCheck)798 for(var i = 0; i < table.colRecords.length; i++) {799 var colRec = table.colRecords[i];800 801 if(colRec.columnName === "_id" || colRec.columnName === "_indexNo") {802 continue;803 }804 var value = doc[colRec.meteorName];805 if(value === undefined || (value instanceof Array) || (value != null && typeof value === 'object')) {806 // missing column ... allow nulls807 if(colRec.nullable === 'N') {808 // Allow NULLs809 var sql = "alter table "+OracleDB.q(sqlTable)+" modify ("+OracleDB.q(colRec.columnName)+" null)";810 var result = self.executeCommand(sql, [], oracleOptions);811 refreshCols = true; 812 }813 }814 }815 816 self._ensureColumnsPostProcess(sqlTable, oracleOptions, refreshCols, postponedBooleanColumns, postponedNullColumns); 817};818OracleDB.prototype.collection = function(name, oracleOptions, callback) {819 var self = this;820 if(typeof oracleOptions == 'function') callback = oracleOptions, oracleOptions = undefined;821 oracleOptions = oracleOptions || Oracle.getDefaultOracleOptions();822 try {823 var collection = new OracleCollection(this, name, oracleOptions);824 825 if(collection.oracleOptions.sqlTable) {826 self._ensureTable(collection.oracleOptions.sqlTable, collection.oracleOptions);827 }828 829 if(callback) callback(null, collection);830 return collection;831 } catch(err) {832 if(callback) return callback(err);833 throw err;834 }...

Full Screen

Full Screen

BooleanFilter.test.js

Source:BooleanFilter.test.js Github

copy

Full Screen

1/*2 * This file is part of ag-gird-components lib.3 * (c) Basis Europe <eu@basis.com>4 *5 * For the full copyright and license information, please view the LICENSE6 * file that was distributed with this source code.7 */8/* eslint-disable no-undef */9describe('#BooleanFilter ', function() {10 let gridOptions = null11 const columnDefs = [12 {13 field: 'booleans',14 filter: 'BooleanFilter',15 filterParams: {16 booleanTrueValue: true, // default17 booleanFalseValue: false, // default18 },19 },20 {21 field: 'booleansYesNo',22 filter: 'BooleanFilter',23 filterParams: {24 booleanTrueValue: 'yes',25 booleanFalseValue: 'no',26 },27 },28 {29 field: 'booleansMixed',30 filter: 'BooleanFilter',31 filterParams: {32 booleanTrueValue: ['yes', true],33 booleanFalseValue: ['no', false],34 },35 },36 ]37 const rowData = [38 {39 booleans: true,40 booleansYesNo: 'yes',41 booleansMixed: true,42 },43 {44 booleans: true,45 booleansYesNo: 'yes',46 booleansMixed: 'yes',47 },48 {49 booleans: false,50 booleansYesNo: 'no',51 booleansMixed: 'no',52 },53 {54 booleans: false,55 booleansYesNo: 'no',56 booleansMixed: false,57 },58 ]59 afterEach(() => {60 gridOptions.api.destroy()61 })62 beforeEach(() => {63 return setupGridForTests({64 components: {65 // eslint-disable-next-line no-undef66 BooleanFilter: Basis.AgGridComponents.BooleanFilter,67 },68 columnDefs,69 rowData,70 }).then(options => {71 gridOptions = options72 })73 })74 it('Gird is initialized successfully', () => {75 expect(gridOptions.api.getDisplayedRowCount()).to.equal(4)76 expect(gridOptions.columnApi.getAllColumns()).to.have.lengthOf(3)77 })78 columnDefs.forEach(column => {79 describe(`#setModel for column "${column.field}"`, () => {80 const models = [{ value: 'true' }, { value: 'false' }]81 models.forEach(model => {82 describe(`can filter "${model.value}" values`, () => {83 beforeEach(() => {84 gridOptions.api.getFilterInstance(column.field).setModel({85 value: model.value,86 })87 gridOptions.api.onFilterChanged()88 gridOptions.api.selectAllFiltered()89 })90 afterEach(() => {91 gridOptions.api.deselectAll()92 gridOptions.api.setFilterModel(null)93 gridOptions.api.onFilterChanged()94 })95 it(`${column.field} filter is active`, () => {96 expect(97 gridOptions.api.getFilterInstance(column.field).isFilterActive()98 ).to.be.true99 })100 it('number of filtered rows is 2', () => {101 const selected = gridOptions.api.getSelectedRows()102 expect(selected, 'selected rows length is 2').to.have.lengthOf(2)103 })104 it(`${column.field} field of each filtered row is "${105 model.value === 'true'106 ? column.filterParams.booleanTrueValue107 : column.filterParams.booleanFalseValue108 }"`, () => {109 const selected = gridOptions.api.getSelectedRows()110 selected.forEach((row, i) => {111 expect(112 row[column.field],113 `rows[${i}].${column.field} is "${114 model.value === 'true'115 ? column.filterParams.booleanTrueValue116 : column.filterParams.booleanFalseValue117 }"`118 ).to.be.oneOf(119 model.value === 'true'120 ? [].concat(column.filterParams.booleanTrueValue)121 : [].concat(column.filterParams.booleanFalseValue)122 )123 })124 })125 })126 })127 })128 })...

Full Screen

Full Screen

BooleanEditor.test.js

Source:BooleanEditor.test.js Github

copy

Full Screen

1/* eslint-disable no-undef */2/*3 * This file is part of ag-gird-components lib.4 * (c) Basis Europe <eu@basis.com>5 *6 * For the full copyright and license information, please view the LICENSE7 * file that was distributed with this source code.8 */9describe('#BooleanEditor ', function() {10 let gridOptions = null11 const columnDefs = [12 {13 field: 'booleans',14 cellEditor: 'BooleanEditor',15 cellEditorParams: {16 booleanTrueValue: true, // default17 booleanFalseValue: false, // default18 },19 },20 {21 field: 'booleansYesNo',22 cellEditor: 'BooleanEditor',23 cellEditorParams: {24 booleanTrueValue: 'yes',25 booleanFalseValue: 'no',26 },27 },28 {29 field: 'booleansMixed',30 cellEditor: 'BooleanEditor',31 cellEditorParams: {32 booleanTrueValue: ['yes', true],33 booleanFalseValue: ['no', false],34 booleanUsedTrueValue: true,35 booleanUsedFalseValue: false,36 },37 },38 ]39 const rowData = [40 {41 booleans: true,42 booleansYesNo: 'yes',43 booleansMixed: true,44 },45 {46 booleans: true,47 booleansYesNo: 'yes',48 booleansMixed: 'yes',49 },50 {51 booleans: false,52 booleansYesNo: 'no',53 booleansMixed: false,54 },55 {56 booleans: false,57 booleansYesNo: 'no',58 booleansMixed: 'no',59 },60 ]61 afterEach(() => {62 gridOptions.api.destroy()63 })64 beforeEach(() => {65 return setupGridForTests({66 components: {67 BooleanEditor: Basis.AgGridComponents.BooleanEditor,68 },69 defaultColDef: {70 editable: true,71 },72 columnDefs,73 rowData,74 }).then(options => {75 gridOptions = options76 })77 })78 it('Gird is initialized successfully', () => {79 expect(gridOptions.api.getDisplayedRowCount()).to.equal(4)80 expect(gridOptions.columnApi.getAllColumns()).to.have.lengthOf(3)81 })82 describe('#editing cells', () => {83 rowData.forEach((row, index) => {84 columnDefs.forEach(column => {85 it(`cell [${index}][${column.field}] content by reversing the value`, () => {86 const api = gridOptions.api87 const colKey = column.field88 const currentValue = row[colKey]89 const cellEditorParams = column.cellEditorParams || {}90 const booleanTrueValue = cellEditorParams.booleanTrueValue91 ? [].concat(cellEditorParams.booleanTrueValue)92 : [true]93 const booleanFalseValue = cellEditorParams.booleanFalseValue94 ? [].concat(cellEditorParams.booleanFalseValue)95 : [false]96 const booleanUsedTrueValue =97 typeof cellEditorParams.booleanUsedTrueValue !== 'undefined'98 ? cellEditorParams.booleanUsedTrueValue99 : booleanTrueValue[0]100 const booleanUsedFalseValue =101 typeof cellEditorParams.booleanUsedFalseValue !== 'undefined'102 ? cellEditorParams.booleanUsedFalseValue103 : booleanFalseValue[0]104 let reverseValue = currentValue105 if (booleanTrueValue.indexOf(currentValue) > -1) {106 reverseValue = reverseBoolean(booleanUsedTrueValue)107 } else {108 reverseValue = reverseBoolean(booleanUsedFalseValue)109 }110 api.startEditingCell({111 rowIndex: index,112 colKey: column.field,113 charPress: reverseValue,114 })115 api.stopEditing()116 const newValue = api.getValue(117 colKey,118 api.getDisplayedRowAtIndex(index)119 )120 expect(newValue).to.deep.equal(reverseValue)121 })122 })123 })124 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestLibrary = require('bestlibrary');2var bestLibrary = new BestLibrary();3console.log(bestLibrary.booleanFalseValue());4var BestLibrary = require('bestlibrary');5var bestLibrary = new BestLibrary();6console.log(bestLibrary.booleanTrueValue());7var BestLibrary = require('bestlibrary');8var bestLibrary = new BestLibrary();9console.log(bestLibrary.booleanTrueValue());10var BestLibrary = require('bestlibrary');11var bestLibrary = new BestLibrary();12console.log(bestLibrary.booleanTrueValue());13var BestLibrary = require('bestlibrary');14var bestLibrary = new BestLibrary();15console.log(bestLibrary.booleanTrueValue());16var BestLibrary = require('bestlibrary');17var bestLibrary = new BestLibrary();18console.log(bestLibrary.booleanTrueValue());19var BestLibrary = require('bestlibrary');20var bestLibrary = new BestLibrary();21console.log(bestLibrary.booleanTrueValue());22var BestLibrary = require('bestlibrary');23var bestLibrary = new BestLibrary();24console.log(bestLibrary.booleanTrueValue());25var BestLibrary = require('bestlibrary');26var bestLibrary = new BestLibrary();27console.log(bestLibrary.booleanTrueValue());28var BestLibrary = require('bestlibrary');29var bestLibrary = new BestLibrary();30console.log(bestLibrary.booleanTrueValue());31var BestLibrary = require('bestlibrary');32var bestLibrary = new BestLibrary();33console.log(bestLibrary.booleanTrueValue());34var BestLibrary = require('bestlibrary');

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestLibrary = require('bestlibrary');2var bestLibrary = new BestLibrary();3bestLibrary.booleanFalseValue();4var BestLibrary = require('bestlibrary');5var bestLibrary = new BestLibrary();6bestLibrary.booleanTrueValue();7var BestLibrary = require('bestlibrary');8var bestLibrary = new BestLibrary();9bestLibrary.booleanTrueValue();10var BestLibrary = require('bestlibrary');11var bestLibrary = new BestLibrary();12bestLibrary.booleanFalseValue();13var BestLibrary = require('bestlibrary');14var bestLibrary = new BestLibrary();15bestLibrary.booleanTrueValue();16var BestLibrary = require('bestlibrary');17var bestLibrary = new BestLibrary();18bestLibrary.booleanFalseValue();19var BestLibrary = require('bestlibrary');20var bestLibrary = new BestLibrary();21bestLibrary.booleanFalseValue();22var BestLibrary = require('bestlibrary');23var bestLibrary = new BestLibrary();24bestLibrary.booleanTrueValue();25var BestLibrary = require('bestlibrary');26var bestLibrary = new BestLibrary();27bestLibrary.booleanFalseValue();28var BestLibrary = require('bestlibrary');29var bestLibrary = new BestLibrary();30bestLibrary.booleanTrueValue();31var BestLibrary = require('bestlibrary');32var bestLibrary = new BestLibrary();33bestLibrary.booleanTrueValue();34var BestLibrary = require('bestlibrary');35var bestLibrary = new BestLibrary();36bestLibrary.booleanTrueValue();

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestLibrary = require('bestlibrary');2var result = BestLibrary.booleanFalseValue();3var BestLibrary = require('bestlibrary');4var result = BestLibrary.booleanTrueValue();5var BestLibrary = require('bestlibrary');6var result = BestLibrary.isString('Hello World');7var BestLibrary = require('bestlibrary');8var result = BestLibrary.isString(1);9var BestLibrary = require('bestlibrary');10var result = BestLibrary.isNumber(1);11var BestLibrary = require('bestlibrary');12var result = BestLibrary.isNumber('Hello World');13var BestLibrary = require('bestlibrary');14var result = BestLibrary.isBoolean(true);15var BestLibrary = require('bestlibrary');16var result = BestLibrary.isBoolean(1);17var BestLibrary = require('bestlibrary');18var result = BestLibrary.isFunction(function(){});19var BestLibrary = require('bestlibrary');20var result = BestLibrary.isFunction(1);21var BestLibrary = require('bestlibrary');22var result = BestLibrary.isArray([]);23var BestLibrary = require('best

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestLibrary = require('bestlibrary');2var booleanFalseValue = bestLibrary.booleanFalseValue();3console.log(booleanFalseValue);4var bestLibrary = require('bestlibrary');5var booleanTrueValue = bestLibrary.booleanTrueValue();6console.log(booleanTrueValue);7var bestLibrary = require('bestlibrary');8var booleanValue = bestLibrary.booleanValue();9console.log(booleanValue);10var bestLibrary = require('bestlibrary');11var booleanValue = bestLibrary.booleanValue();12console.log(booleanValue);13var bestLibrary = require('bestlibrary');14var booleanValue = bestLibrary.booleanValue();15console.log(booleanValue);16var bestLibrary = require('bestlibrary');17var booleanValue = bestLibrary.booleanValue();18console.log(booleanValue);19var bestLibrary = require('bestlibrary');20var booleanValue = bestLibrary.booleanValue();21console.log(booleanValue);22var bestLibrary = require('bestlibrary');23var booleanValue = bestLibrary.booleanValue();24console.log(booleanValue);25var bestLibrary = require('bestlibrary');26var booleanValue = bestLibrary.booleanValue();27console.log(booleanValue);28var bestLibrary = require('bestlibrary');29var booleanValue = bestLibrary.booleanValue();30console.log(booleanValue);31var bestLibrary = require('bestlibrary');32var booleanValue = bestLibrary.booleanValue();33console.log(booleanValue);34var bestLibrary = require('bestlibrary');35var booleanValue = bestLibrary.booleanValue();36console.log(booleanValue);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestLibrary = require('bestlibrary');2var bestLibrary = new BestLibrary();3var booleanFalseValue = bestLibrary.booleanFalseValue();4console.log("booleanFalseValue: ", booleanFalseValue);5var BestLibrary = require('bestlibrary');6var bestLibrary = new BestLibrary();7var booleanTrueValue = bestLibrary.booleanTrueValue();8console.log("booleanTrueValue: ", booleanTrueValue);9var BestLibrary = require('bestlibrary');10var bestLibrary = new BestLibrary();11var booleanTrueValue = bestLibrary.booleanTrueValue();12console.log("booleanTrueValue: ", booleanTrueValue);13var BestLibrary = require('bestlibrary');14var bestLibrary = new BestLibrary();15var string = bestLibrary.functionThatReturnsAString();16console.log("string: ", string);17var BestLibrary = require('bestlibrary');18var bestLibrary = new BestLibrary();19var array = bestLibrary.functionThatReturnsAnArray();20console.log("array: ", array);21var BestLibrary = require('bestlibrary');22var bestLibrary = new BestLibrary();23var object = bestLibrary.functionThatReturnsAnObject();24console.log("object: ", object);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestLibraryEver = require("bestlibraryever");2var bl = new BestLibraryEver();3var result = bl.booleanFalseValue();4console.log("Result: " + result);5var BestLibraryEver = require("bestlibraryever");6var bl = new BestLibraryEver();7var result = bl.booleanTrueValue();8console.log("Result: " + result);9var BestLibraryEver = require("bestlibraryever");10var bl = new BestLibraryEver();11var result = bl.stringEmptyValue();12console.log("Result: " + result);13var BestLibraryEver = require("bestlibraryever");14var bl = new BestLibraryEver();15var result = bl.stringNullValue();16console.log("Result: " + result);17var BestLibraryEver = require("bestlibraryever");18var bl = new BestLibraryEver();19var result = bl.stringSpaceValue();20console.log("Result: " + result);21var BestLibraryEver = require("bestlibraryever");22var bl = new BestLibraryEver();23var result = bl.stringStringValue();24console.log("Result: " + result);25var BestLibraryEver = require("bestlibraryever");26var bl = new BestLibraryEver();27var result = bl.numberZeroValue();28console.log("Result: " + result);29var BestLibraryEver = require("bestlibraryever");30var bl = new BestLibraryEver();31var result = bl.numberNullValue();32console.log("Result: " + result);33var BestLibraryEver = require("bestlibraryever");34var bl = new BestLibraryEver();35var result = bl.numberMaxValue();36console.log("Result: " + result);

Full Screen

Using AI Code Generation

copy

Full Screen

1var booleanFalseValue = require('BestLibrary').booleanFalseValue;2var booleanFalseValue = require('BestLibrary').booleanFalseValue;3var booleanFalseValue = require('BestLibrary').booleanFalseValue;4var booleanFalseValue = require('BestLibrary').booleanFalseValue;5var booleanFalseValue = require('BestLibrary').booleanFalseValue;6var booleanFalseValue = require('BestLibrary').booleanFalseValue;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful