foxhound 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxhound",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "A Database Query generation library.",
5
5
  "main": "source/FoxHound.js",
6
6
  "scripts": {
@@ -32,12 +32,92 @@ var FoxHoundDialectMSSQL = function(pFable)
32
32
  */
33
33
  var generateTableName = function(pParameters)
34
34
  {
35
- if (pParameters.scope && pParameters.scope.indexOf('`') >= 0)
36
- return ' '+pParameters.scope+'';
37
- else
38
- return ' `'+pParameters.scope+'`';
35
+ // Every Foxhound query has a table name; this puts it on here even if there are no columns
36
+ // Which occurs when you generate a query like SELECT COUNT(*) FROM SomeTable;
37
+ if (!pParameters.query.hasOwnProperty('parameterTypes'))
38
+ {
39
+ pParameters.query.parameterTypes = {};
40
+ }
41
+ return ' '+pParameters.scope;
39
42
  };
40
43
 
44
+ var generateMSSQLParameterTypeEntry = function(pParameters, pColumnParameterName, pColumn)
45
+ {
46
+ // Lazily create the parameterTypes object if it doesn't exist
47
+ if (!pParameters.query.hasOwnProperty('parameterTypes'))
48
+ {
49
+ pParameters.query.parameterTypes = {};
50
+ }
51
+ // Find the column parameter type for our prepared statement
52
+ let tmpColumnParameterTypeString = 'VarChar';
53
+ if (typeof(pColumn) == 'object')
54
+ {
55
+ // See if it has a type, set the type string
56
+ tmpColumnParameterTypeString = pColumn.Type;
57
+ }
58
+ else if (typeof(pColumn) == 'string')
59
+ {
60
+ var tmpSchema = Array.isArray(pParameters.query.schema) ? pParameters.query.schema : [];
61
+ for (let i = 0; i < tmpSchema.length; i++)
62
+ {
63
+ if (tmpSchema[i].Column == pColumn)
64
+ {
65
+ tmpColumnParameterTypeString = tmpSchema[i].Type;
66
+ break;
67
+ }
68
+ }
69
+ }
70
+ else
71
+ {
72
+ _Fable.log.warn(`Meadow MSSQL query attempted to add a parameter type but no valid column schema entry object or column name was passed; parameter name ${pColumnParameterName}.`);
73
+ }
74
+
75
+ if ((tmpColumnParameterTypeString == null) || (tmpColumnParameterTypeString == undefined))
76
+ {
77
+ return false;
78
+ }
79
+ switch (tmpColumnParameterTypeString)
80
+ {
81
+ case 'AutoIdentity':
82
+ case 'CreateIDUser':
83
+ case 'UpdateIDUser':
84
+ case 'DeleteIDUser':
85
+
86
+ case 'Integer':
87
+ pParameters.query.parameterTypes[pColumnParameterName] = 'Int';
88
+ break;
89
+
90
+ case 'Deleted':
91
+ case 'Boolean':
92
+ pParameters.query.parameterTypes[pColumnParameterName] = 'TinyInt';
93
+ break;
94
+
95
+ case 'Decimal':
96
+ pParameters.query.parameterTypes[pColumnParameterName] = 'Decimal';
97
+ break;
98
+
99
+ case 'String':
100
+ case 'AutoGUID':
101
+ pParameters.query.parameterTypes[pColumnParameterName] = 'Char';
102
+ break;
103
+
104
+ case 'CreateDate':
105
+ case 'UpdateDate':
106
+ case 'DeleteDate':
107
+
108
+ case 'DateTime':
109
+ pParameters.query.parameterTypes[pColumnParameterName] = 'DateTime';
110
+ break;
111
+
112
+ default:
113
+ // TODO: This might should throw? It would mean a new type was added to stricture we don't know about.
114
+ pParameters.query.parameterTypes[pColumnParameterName] = tmpColumnParameterTypeString;
115
+ return false;
116
+ }
117
+
118
+ return true;
119
+ }
120
+
41
121
  /**
42
122
  * Generate a field list from the array of dataElements
43
123
  *
@@ -99,36 +179,12 @@ var FoxHoundDialectMSSQL = function(pFable)
99
179
  return tmpFieldList;
100
180
  };
101
181
 
102
- const SURROUNDING_QUOTES_AND_WHITESPACE_REGEX = /^[` ]+|[` ]+$/g;
103
-
104
- const cleanseQuoting = (str) =>
105
- {
106
- return str.replace(SURROUNDING_QUOTES_AND_WHITESPACE_REGEX, '');
107
- };
108
-
109
182
  /**
110
183
  * Ensure a field name is properly escaped.
111
184
  */
112
185
  var generateSafeFieldName = function(pFieldName)
113
186
  {
114
- let pFieldNames = pFieldName.split('.');
115
- if (pFieldNames.length > 1)
116
- {
117
- const cleansedFieldName = cleanseQuoting(pFieldNames[1]);
118
- if (cleansedFieldName === '*')
119
- {
120
- // do not put * as `*`
121
- return "`" + cleanseQuoting(pFieldNames[0]) + "`.*";
122
- }
123
- return "`" + cleanseQuoting(pFieldNames[0]) + "`.`" + cleansedFieldName + "`";
124
- }
125
- const cleansedFieldName = cleanseQuoting(pFieldNames[0]);
126
- if (cleansedFieldName === '*')
127
- {
128
- // do not put * as `*`
129
- return '*';
130
- }
131
- return "`" + cleanseQuoting(pFieldNames[0]) + "`";
187
+ return pFieldName;
132
188
  }
133
189
 
134
190
  /**
@@ -231,8 +287,10 @@ var FoxHoundDialectMSSQL = function(pFable)
231
287
  {
232
288
  tmpColumnParameter = tmpFilter[i].Parameter+'_w'+i;
233
289
  // Add the column name, operator and parameter name to the list of where value parenthetical
234
- tmpWhere += ' '+tmpFilter[i].Column+' '+tmpFilter[i].Operator+' ( :'+tmpColumnParameter+' )';
290
+ tmpWhere += ' '+tmpFilter[i].Column+' '+tmpFilter[i].Operator+' ( @'+tmpColumnParameter+' )';
235
291
  pParameters.query.parameters[tmpColumnParameter] = tmpFilter[i].Value;
292
+ // Find the column in the schema
293
+ generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpFilter[i].Parameter)
236
294
  }
237
295
  else if (tmpFilter[i].Operator === 'IS NULL')
238
296
  {
@@ -248,8 +306,9 @@ var FoxHoundDialectMSSQL = function(pFable)
248
306
  {
249
307
  tmpColumnParameter = tmpFilter[i].Parameter+'_w'+i;
250
308
  // Add the column name, operator and parameter name to the list of where value parenthetical
251
- tmpWhere += ' '+tmpFilter[i].Column+' '+tmpFilter[i].Operator+' :'+tmpColumnParameter;
309
+ tmpWhere += ' '+tmpFilter[i].Column+' '+tmpFilter[i].Operator+' @'+tmpColumnParameter;
252
310
  pParameters.query.parameters[tmpColumnParameter] = tmpFilter[i].Value;
311
+ generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpFilter[i].Parameter)
253
312
  }
254
313
  }
255
314
 
@@ -305,14 +364,18 @@ var FoxHoundDialectMSSQL = function(pFable)
305
364
  return '';
306
365
  }
307
366
 
308
- var tmpLimit = ' LIMIT';
367
+ var tmpLimit = ' OFFSET ';
309
368
  // If there is a begin record, we'll pass that in as well.
310
369
  if (pParameters.begin !== false)
311
370
  {
312
- tmpLimit += ' ' + pParameters.begin + ',';
371
+ tmpLimit += pParameters.begin;
372
+ }
373
+ else
374
+ {
375
+ tmpLimit += '0';
313
376
  }
314
377
  // Cap is required for a limit clause.
315
- tmpLimit += ' ' + pParameters.cap;
378
+ tmpLimit += ` ROWS FETCH NEXT ${pParameters.cap} ROWS ONLY`;
316
379
 
317
380
  return tmpLimit;
318
381
  };
@@ -420,16 +483,18 @@ var FoxHoundDialectMSSQL = function(pFable)
420
483
  // This is the user ID, which we hope is in the query.
421
484
  // This is how to deal with a normal column
422
485
  var tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
423
- tmpUpdate += ' '+tmpColumn+' = :'+tmpColumnParameter;
486
+ tmpUpdate += ' '+tmpColumn+' = @'+tmpColumnParameter;
424
487
  // Set the query parameter
425
488
  pParameters.query.parameters[tmpColumnParameter] = pParameters.query.IDUser;
489
+ generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpColumn)
426
490
  break;
427
491
  default:
428
492
  var tmpColumnDefaultParameter = tmpColumn+'_'+tmpCurrentColumn;
429
- tmpUpdate += ' '+tmpColumn+' = :'+tmpColumnDefaultParameter;
493
+ tmpUpdate += ' '+tmpColumn+' = @'+tmpColumnDefaultParameter;
430
494
 
431
495
  // Set the query parameter
432
496
  pParameters.query.parameters[tmpColumnDefaultParameter] = tmpRecords[0][tmpColumn];
497
+ generateMSSQLParameterTypeEntry(pParameters, tmpColumnDefaultParameter, tmpSchemaEntry)
433
498
  break;
434
499
  }
435
500
 
@@ -493,9 +558,10 @@ var FoxHoundDialectMSSQL = function(pFable)
493
558
  // This is the user ID, which we hope is in the query.
494
559
  // This is how to deal with a normal column
495
560
  var tmpColumnParameter = tmpSchemaEntry.Column+'_'+tmpCurrentColumn;
496
- tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = :'+tmpColumnParameter;
561
+ tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = @'+tmpColumnParameter;
497
562
  // Set the query parameter
498
563
  pParameters.query.parameters[tmpColumnParameter] = pParameters.query.IDUser;
564
+ generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpSchemaEntry)
499
565
  break;
500
566
  default:
501
567
  //DON'T allow update of other fields in this query
@@ -560,8 +626,9 @@ var FoxHoundDialectMSSQL = function(pFable)
560
626
  break;
561
627
  case 'UpdateIDUser':
562
628
  var tmpColumnParameter = tmpSchemaEntry.Column+'_'+tmpCurrentColumn;
563
- tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = :'+tmpColumnParameter;
629
+ tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = @'+tmpColumnParameter;
564
630
  pParameters.query.parameters[tmpColumnParameter] = pParameters.query.IDUser;
631
+ generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpSchemaEntry)
565
632
  break;
566
633
  default:
567
634
  //DON'T allow update of other fields in this query
@@ -646,9 +713,10 @@ var FoxHoundDialectMSSQL = function(pFable)
646
713
  var buildDefaultDefinition = function()
647
714
  {
648
715
  var tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
649
- tmpCreateSet += ' :'+tmpColumnParameter;
716
+ tmpCreateSet += ' @'+tmpColumnParameter;
650
717
  // Set the query parameter
651
718
  pParameters.query.parameters[tmpColumnParameter] = tmpRecords[0][tmpColumn];
719
+ generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpSchemaEntry)
652
720
  };
653
721
 
654
722
  var tmpColumnParameter;
@@ -681,9 +749,10 @@ var FoxHoundDialectMSSQL = function(pFable)
681
749
  {
682
750
  // This is an autoidentity, so we don't parameterize it and just pass in NULL
683
751
  tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
684
- tmpCreateSet += ' :'+tmpColumnParameter;
752
+ tmpCreateSet += ' @'+tmpColumnParameter;
685
753
  // Set the query parameter
686
754
  pParameters.query.parameters[tmpColumnParameter] = pParameters.query.UUID;
755
+ generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpSchemaEntry)
687
756
  }
688
757
  break;
689
758
  case 'UpdateDate':
@@ -711,9 +780,10 @@ var FoxHoundDialectMSSQL = function(pFable)
711
780
  // This is the user ID, which we hope is in the query.
712
781
  // This is how to deal with a normal column
713
782
  tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
714
- tmpCreateSet += ' :'+tmpColumnParameter;
783
+ tmpCreateSet += ' @'+tmpColumnParameter;
715
784
  // Set the query parameter
716
785
  pParameters.query.parameters[tmpColumnParameter] = pParameters.query.IDUser;
786
+ generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpSchemaEntry)
717
787
  }
718
788
  break;
719
789
  default:
@@ -929,7 +999,7 @@ var FoxHoundDialectMSSQL = function(pFable)
929
999
  }
930
1000
  }
931
1001
 
932
- return `SELECT COUNT(${tmpOptDistinct}${tmpFieldList || '*'}) AS RowCount FROM${tmpTableName}${tmpJoin}${tmpWhere};`;
1002
+ return `SELECT COUNT(${tmpOptDistinct}${tmpFieldList || '*'}) AS Row_Count FROM${tmpTableName}${tmpJoin}${tmpWhere};`;
933
1003
  };
934
1004
 
935
1005
  var tmpDialect = ({
@@ -24,7 +24,9 @@ var _AnimalSchema = (
24
24
  { Column: "UpdatingIDUser", Type:"UpdateIDUser" },
25
25
  { Column: "Deleted", Type:"Deleted" },
26
26
  { Column: "DeletingIDUser", Type:"DeleteIDUser" },
27
- { Column: "DeleteDate", Type:"DeleteDate" }
27
+ { Column: "DeleteDate", Type:"DeleteDate" },
28
+ { Column: "Name", Type:"String" },
29
+ { Column: "Age", Type:"Integer" }
28
30
  ]);
29
31
 
30
32
  var _AnimalSchemaWithoutDeleted = (
@@ -89,7 +91,7 @@ suite
89
91
  // This is the query generated by the MSSQL dialect
90
92
  _Fable.log.trace('Create Query', tmpQuery.query);
91
93
  Expect(tmpQuery.query.body)
92
- .to.equal("INSERT INTO `Animal` ( IDAnimal, Name, Age) VALUES ( :IDAnimal_0, :Name_1, :Age_2);");
94
+ .to.equal("INSERT INTO Animal ( IDAnimal, Name, Age) VALUES ( @IDAnimal_0, @Name_1, @Age_2);");
93
95
  }
94
96
  );
95
97
  test
@@ -120,7 +122,7 @@ suite
120
122
  // This is the query generated by the MSSQL dialect
121
123
  _Fable.log.trace('Simple Select Query', tmpQuery.query);
122
124
  Expect(tmpQuery.query.body)
123
- .to.equal('SELECT `Animal`.* FROM `Animal` ORDER BY Cost DESC;');
125
+ .to.equal('SELECT Animal.* FROM Animal ORDER BY Cost DESC;');
124
126
  }
125
127
  );
126
128
  test
@@ -136,7 +138,7 @@ suite
136
138
  // This is the query generated by the MSSQL dialect
137
139
  _Fable.log.trace('Simple Select Query', tmpQuery.query);
138
140
  Expect(tmpQuery.query.body)
139
- .to.equal('SELECT DISTINCT `Animal`.* FROM `Animal` ORDER BY Cost DESC;');
141
+ .to.equal('SELECT DISTINCT Animal.* FROM Animal ORDER BY Cost DESC;');
140
142
  }
141
143
  );
142
144
  test
@@ -158,8 +160,7 @@ suite
158
160
  // This is the query generated by the MSSQL dialect
159
161
  _Fable.log.trace('Select Query', tmpQuery.query);
160
162
  Expect(tmpQuery.query.body)
161
- .to.equal('SELECT `Name`, `Age`, `Cost` FROM `Animal` WHERE Age = :Age_w0 ORDER BY Age, Cost LIMIT 0, 10;');
162
- }
163
+ .to.equal('SELECT Name, Age, Cost FROM Animal WHERE Age = @Age_w0 ORDER BY Age, Cost OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
163
164
  );
164
165
  test
165
166
  (
@@ -180,8 +181,7 @@ suite
180
181
  // This is the query generated by the MSSQL dialect
181
182
  _Fable.log.trace('Select Query', tmpQuery.query);
182
183
  Expect(tmpQuery.query.body)
183
- .to.equal('SELECT *, `Name`, `Age`, `Cost`, `Animal`.* FROM `Animal` WHERE Age = :Age_w0 ORDER BY Age, Cost LIMIT 0, 10;');
184
- }
184
+ .to.equal('SELECT *, Name, Age, Cost, Animal.* FROM Animal WHERE Age = @Age_w0 ORDER BY Age, Cost OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
185
185
  );
186
186
  test
187
187
  (
@@ -200,13 +200,13 @@ suite
200
200
  .addFilter('', '', ')')
201
201
  .addFilter('Description', '', 'IS NOT NULL')
202
202
  .addFilter('IDOffice', [10, 11, 15, 18, 22], 'IN');
203
- tmpQuery.setLogLevel(3).addSort('Age');
203
+ tmpQuery.setLogLevel(0).addSort('Age');
204
204
  // Build the query
205
205
  tmpQuery.buildReadQuery();
206
206
  // This is the query generated by the MSSQL dialect
207
207
  _Fable.log.trace('Select Query', tmpQuery.query);
208
208
  Expect(tmpQuery.query.body)
209
- .to.equal('SELECT `Name`, `Age`, `Cost` FROM `Animal` WHERE Age = :Age_w0 AND ( Color = :Color_w2 OR Color = :Color_w3 ) AND Description IS NOT NULL AND IDOffice IN ( :IDOffice_w6 ) ORDER BY Age LIMIT 100;');
209
+ .to.equal('SELECT Name, Age, Cost FROM Animal WHERE Age = @Age_w0 AND ( Color = @Color_w2 OR Color = @Color_w3 ) AND Description IS NOT NULL AND IDOffice IN ( @IDOffice_w6 ) ORDER BY Age OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
210
210
  }
211
211
  );
212
212
  test
@@ -228,8 +228,7 @@ suite
228
228
  // This is the query generated by the MSSQL dialect
229
229
  _Fable.log.trace('Custom Select Query', tmpQuery.query);
230
230
  Expect(tmpQuery.query.body)
231
- .to.equal('SELECT Name, Age * 5, Cost FROM `Animal` WHERE Age = :Age_w0 LIMIT 0, 10;');
232
- }
231
+ .to.equal('SELECT Name, Age * 5, Cost FROM Animal WHERE Age = @Age_w0 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
233
232
  );
234
233
  test
235
234
  (
@@ -251,8 +250,7 @@ suite
251
250
  // This is the query generated by the MSSQL dialect
252
251
  _Fable.log.trace('Custom Select Query', tmpQuery.query);
253
252
  Expect(tmpQuery.query.body)
254
- .to.equal('SELECT Name, Age * 5, Cost FROM `Animal` WHERE Age = :Age_w0 LIMIT 0, 10;');
255
- }
253
+ .to.equal('SELECT Name, Age * 5, Cost FROM Animal WHERE Age = @Age_w0 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
256
254
  );
257
255
  test
258
256
  (
@@ -309,7 +307,7 @@ suite
309
307
  // This is the query generated by the MSSQL dialect
310
308
  _Fable.log.trace('Custom Count Query', tmpQuery.query);
311
309
  Expect(tmpQuery.query.body)
312
- .to.equal('SELECT COUNT(*) AS RowCount FROM `Animal` WHERE Age = :Age_w0;');
310
+ .to.equal('SELECT COUNT(*) AS RowCount FROM Animal WHERE Age = @Age_w0;');
313
311
  }
314
312
  );
315
313
  test
@@ -328,7 +326,7 @@ suite
328
326
  // This is the query generated by the MSSQL dialect
329
327
  _Fable.log.trace('Custom Count Query', tmpQuery.query);
330
328
  Expect(tmpQuery.query.body)
331
- .to.equal('SELECT COUNT(*) AS RowCount FROM `Animal` WHERE Age = :Age_w0;');
329
+ .to.equal('SELECT COUNT(*) AS RowCount FROM Animal WHERE Age = @Age_w0;');
332
330
  }
333
331
  );
334
332
  test
@@ -347,7 +345,7 @@ suite
347
345
  // This is the query generated by the MSSQL dialect
348
346
  _Fable.log.trace('Update Query', tmpQuery.query);
349
347
  Expect(tmpQuery.query.body)
350
- .to.equal('UPDATE `Animal` SET Age = :Age_0, Color = :Color_1 WHERE IDAnimal = :IDAnimal_w0;');
348
+ .to.equal('UPDATE Animal SET Age = @Age_0, Color = @Color_1 WHERE IDAnimal = @IDAnimal_w0;');
351
349
  }
352
350
  );
353
351
  test
@@ -381,7 +379,7 @@ suite
381
379
  // This is the query generated by the MSSQL dialect
382
380
  _Fable.log.trace('Delete Query', tmpQuery.query);
383
381
  Expect(tmpQuery.query.body)
384
- .to.equal('DELETE FROM `Animal` WHERE IDAnimal = :IDAnimal_w0;');
382
+ .to.equal('DELETE FROM Animal WHERE IDAnimal = @IDAnimal_w0;');
385
383
  }
386
384
  );
387
385
  test
@@ -398,7 +396,7 @@ suite
398
396
  // This is the query generated by the MSSQL dialect
399
397
  _Fable.log.trace('Count Query', tmpQuery.query);
400
398
  Expect(tmpQuery.query.body)
401
- .to.equal('SELECT COUNT(*) AS RowCount FROM `Animal`;');
399
+ .to.equal('SELECT COUNT(*) AS Row_Count FROM Animal;');
402
400
  }
403
401
  );
404
402
  test
@@ -417,7 +415,8 @@ suite
417
415
  // This is the query generated by the MSSQL dialect
418
416
  _Fable.log.trace('Count Distinct Query', tmpQuery.query);
419
417
  Expect(tmpQuery.query.body)
420
- .to.equal('SELECT COUNT(DISTINCT `Animal`.`IDAnimal`) AS RowCount FROM `Animal` WHERE `Animal`.Deleted = :Deleted_w0;');
418
+ // RowCount is a reserved word for MSSQL so we need to change it to Row_Count
419
+ .to.equal('SELECT COUNT(DISTINCT Animal.IDAnimal) AS Row_Count FROM Animal WHERE Animal.Deleted = @Deleted_w0;');
421
420
  }
422
421
  );
423
422
  test
@@ -435,7 +434,7 @@ suite
435
434
  // This is the query generated by the MSSQL dialect
436
435
  _Fable.log.trace('Count Distinct Query', tmpQuery.query);
437
436
  Expect(tmpQuery.query.body)
438
- .to.equal('SELECT COUNT(*) AS RowCount FROM `Animal`;');
437
+ .to.equal('SELECT COUNT(*) AS Row_Count FROM Animal;');
439
438
  }
440
439
  );
441
440
  test
@@ -446,7 +445,7 @@ suite
446
445
  var tmpQuery = libFoxHound.new(_Fable)
447
446
  .setDialect('MSSQL')
448
447
  .setScope('Animal')
449
- .setDataElements(['Name', 'Age', 'Cost']);
448
+ .setDataElements(['Name']);
450
449
  tmpQuery.setDistinct(true);
451
450
 
452
451
  // Build the query
@@ -454,7 +453,7 @@ suite
454
453
  // This is the query generated by the MSSQL dialect
455
454
  _Fable.log.trace('Count Distinct Query', tmpQuery.query);
456
455
  Expect(tmpQuery.query.body)
457
- .to.equal('SELECT COUNT(DISTINCT `Name`, `Age`, `Cost`) AS RowCount FROM `Animal`;');
456
+ .to.equal('SELECT COUNT(DISTINCT Name) AS Row_Count FROM Animal;');
458
457
  }
459
458
  );
460
459
  }
@@ -494,7 +493,7 @@ suite
494
493
  // This is the query generated by the MSSQL dialect
495
494
  _Fable.log.trace('Create Query', tmpQuery.query);
496
495
  Expect(tmpQuery.query.body)
497
- .to.equal("INSERT INTO `Animal` ( IDAnimal, GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, Name, Age) VALUES ( NULL, :GUIDAnimal_1, NOW(3), :CreatingIDUser_3, NOW(3), :UpdatingIDUser_5, :Deleted_6, :Name_7, :Age_8);");
496
+ .to.equal("INSERT INTO Animal ( IDAnimal, GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, Name, Age) VALUES ( NULL, @GUIDAnimal_1, NOW(3), @CreatingIDUser_3, NOW(3), @UpdatingIDUser_5, @Deleted_6, @Name_7, @Age_8);");
498
497
  }
499
498
  );
500
499
  test
@@ -526,7 +525,7 @@ suite
526
525
  // This is the query generated by the MSSQL dialect
527
526
  _Fable.log.trace('Create Query', tmpQuery.query);
528
527
  Expect(tmpQuery.query.body)
529
- .to.equal("INSERT INTO `Animal` ( IDAnimal, GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, Name, Age) VALUES ( NULL, :GUIDAnimal_1, NOW(3), :CreatingIDUser_3, NOW(3), :UpdatingIDUser_5, :Deleted_6, :Name_7, :Age_8);");
528
+ .to.equal("INSERT INTO Animal ( IDAnimal, GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, Name, Age) VALUES ( NULL, @GUIDAnimal_1, NOW(3), @CreatingIDUser_3, NOW(3), @UpdatingIDUser_5, @Deleted_6, @Name_7, @Age_8);");
530
529
  }
531
530
  );
532
531
  test
@@ -562,7 +561,7 @@ suite
562
561
  // This is the query generated by the MSSQL dialect
563
562
  _Fable.log.trace('Create Query (AutoIdentity disabled)', tmpQuery.query);
564
563
  Expect(tmpQuery.query.body)
565
- .to.equal("INSERT INTO `Animal` ( IDAnimal, GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, DeletingIDUser, DeleteDate, Name, Age) VALUES ( :IDAnimal_0, :GUIDAnimal_1, :CreateDate_2, :CreatingIDUser_3, :UpdateDate_4, :UpdatingIDUser_5, :Deleted_6, :DeletingIDUser_7, :DeleteDate_8, :Name_9, :Age_10);");
564
+ .to.equal("INSERT INTO Animal ( IDAnimal, GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, DeletingIDUser, DeleteDate, Name, Age) VALUES ( @IDAnimal_0, @GUIDAnimal_1, @CreateDate_2, @CreatingIDUser_3, @UpdateDate_4, @UpdatingIDUser_5, @Deleted_6, @DeletingIDUser_7, @DeleteDate_8, @Name_9, @Age_10);");
566
565
  }
567
566
  );
568
567
  test
@@ -583,7 +582,7 @@ suite
583
582
  // This is the query generated by the MSSQL dialect
584
583
  _Fable.log.trace('Select Query', tmpQuery.query);
585
584
  Expect(tmpQuery.query.body)
586
- .to.equal('SELECT `Name`, `Age`, `Cost` FROM `Animal` WHERE `Animal`.Deleted = :Deleted_w0 LIMIT 100;');
585
+ .to.equal('SELECT Name, Age, Cost FROM Animal WHERE Animal.Deleted = @Deleted_w0 OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
587
586
  }
588
587
  );
589
588
  test
@@ -605,7 +604,7 @@ suite
605
604
  // This is the query generated by the MSSQL dialect
606
605
  _Fable.log.trace('Select Query', tmpQuery.query);
607
606
  Expect(tmpQuery.query.body)
608
- .to.equal('SELECT DISTINCT `Name`, `Age`, `Cost` FROM `Animal` WHERE `Animal`.Deleted = :Deleted_w0 LIMIT 100;');
607
+ .to.equal('SELECT DISTINCT Name, Age, Cost FROM Animal WHERE Animal.Deleted = @Deleted_w0 OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
609
608
  }
610
609
  );
611
610
  test
@@ -634,7 +633,7 @@ suite
634
633
  // This is the query generated by the MSSQL dialect
635
634
  _Fable.log.trace('Select Query', tmpQuery.query);
636
635
  Expect(tmpQuery.query.body)
637
- .to.equal('SELECT `Name`, `Age`, `Cost` FROM `Animal` WHERE Age = :Age_w0 AND ( Color = :Color_w2 OR Color = :Color_w3 ) AND Description IS NOT NULL AND IDOffice IN ( :IDOffice_w6 ) AND Deleted = :Deleted_w7 LIMIT 100;');
636
+ .to.equal('SELECT Name, Age, Cost FROM Animal WHERE Age = @Age_w0 AND ( Color = @Color_w2 OR Color = @Color_w3 ) AND Description IS NOT NULL AND IDOffice IN ( @IDOffice_w6 ) AND Deleted = @Deleted_w7 OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
638
637
  }
639
638
  );
640
639
  test
@@ -656,7 +655,7 @@ suite
656
655
  // This is the query generated by the MSSQL dialect
657
656
  _Fable.log.trace('Select Query', tmpQuery.query);
658
657
  Expect(tmpQuery.query.body)
659
- .to.equal('SELECT `Name`, `Age`, `Cost` FROM `Animal` LIMIT 100;');
658
+ .to.equal('SELECT Name, Age, Cost FROM Animal OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
660
659
  }
661
660
  );
662
661
  test
@@ -677,7 +676,7 @@ suite
677
676
  // This is the query generated by the MSSQL dialect
678
677
  _Fable.log.trace('Delete Query', tmpQuery.query);
679
678
  Expect(tmpQuery.query.body)
680
- .to.equal('UPDATE `Animal` SET UpdateDate = NOW(3), Deleted = 1, DeletingIDUser = :DeletingIDUser_2, DeleteDate = NOW(3) WHERE IDAnimal = :IDAnimal_w0 AND `Animal`.Deleted = :Deleted_w1;');
679
+ .to.equal('UPDATE Animal SET UpdateDate = NOW(3), Deleted = 1, DeletingIDUser = @DeletingIDUser_2, DeleteDate = NOW(3) WHERE IDAnimal = @IDAnimal_w0 AND Animal.Deleted = @Deleted_w1;');
681
680
  }
682
681
  );
683
682
  test
@@ -705,7 +704,7 @@ suite
705
704
  // This is the query generated by the MSSQL dialect
706
705
  _Fable.log.trace('Update Query', tmpQuery.query);
707
706
  Expect(tmpQuery.query.body)
708
- .to.equal('UPDATE `Animal` SET GUIDAnimal = :GUIDAnimal_0, UpdateDate = NOW(3), UpdatingIDUser = :UpdatingIDUser_2, Name = :Name_3, Age = :Age_4 WHERE IDAnimal = :IDAnimal_w0;');
707
+ .to.equal('UPDATE Animal SET GUIDAnimal = @GUIDAnimal_0, UpdateDate = NOW(3), UpdatingIDUser = @UpdatingIDUser_2, Name = @Name_3, Age = @Age_4 WHERE IDAnimal = @IDAnimal_w0;');
709
708
  }
710
709
  );
711
710
  test
@@ -735,7 +734,7 @@ suite
735
734
  // This is the query generated by the MSSQL dialect
736
735
  _Fable.log.trace('Update Query', tmpQuery.query);
737
736
  Expect(tmpQuery.query.body)
738
- .to.equal('UPDATE `Animal` SET GUIDAnimal = :GUIDAnimal_0, Name = :Name_1, Age = :Age_2 WHERE IDAnimal = :IDAnimal_w0;');
737
+ .to.equal('UPDATE Animal SET GUIDAnimal = @GUIDAnimal_0, Name = @Name_1, Age = @Age_2 WHERE IDAnimal = @IDAnimal_w0;');
739
738
  }
740
739
  );
741
740
  test
@@ -757,7 +756,7 @@ suite
757
756
  // This is the query generated by the MSSQL dialect
758
757
  _Fable.log.trace('Delete Query', tmpQuery.query);
759
758
  Expect(tmpQuery.query.body)
760
- .to.equal('DELETE FROM `Animal` WHERE IDAnimal = :IDAnimal_w0;');
759
+ .to.equal('DELETE FROM Animal WHERE IDAnimal = @IDAnimal_w0;');
761
760
  }
762
761
  );
763
762
  test
@@ -777,7 +776,7 @@ suite
777
776
  CreatingIDUser:false,
778
777
  UpdateDate:false,
779
778
  UpdatingIDUser:false,
780
- Deleted:false,
779
+ Deleted:0,
781
780
  DeletingIDUser:false,
782
781
  DeleteDate:false,
783
782
  Name:'Froo Froo',
@@ -789,7 +788,7 @@ suite
789
788
  // This is the query generated by the MSSQL dialect
790
789
  _Fable.log.trace('Update Query', tmpQuery.query);
791
790
  Expect(tmpQuery.query.body)
792
- .to.equal('UPDATE `Animal` SET GUIDAnimal = :GUIDAnimal_0, UpdateDate = NOW(3), UpdatingIDUser = :UpdatingIDUser_2, Deleted = :Deleted_3, Name = :Name_4, Age = :Age_5 WHERE IDAnimal = :IDAnimal_w0 AND Deleted = :Deleted_w1;');
791
+ .to.equal('UPDATE Animal SET GUIDAnimal = @GUIDAnimal_0, UpdateDate = NOW(3), UpdatingIDUser = @UpdatingIDUser_2, Deleted = @Deleted_3, Name = @Name_4, Age = @Age_5 WHERE IDAnimal = @IDAnimal_w0 AND Deleted = @Deleted_w1;');
793
792
  }
794
793
  );
795
794
  test
@@ -811,7 +810,7 @@ suite
811
810
  // This is the query generated by the MSSQL dialect
812
811
  _Fable.log.trace('Delete Query', tmpQuery.query);
813
812
  Expect(tmpQuery.query.body)
814
- .to.equal('UPDATE `Animal` SET UpdateDate = NOW(3), Deleted = 1, DeletingIDUser = :DeletingIDUser_2, DeleteDate = NOW(3) WHERE IDAnimal = :IDAnimal_w0 AND `Animal`.Deleted = :Deleted_w1;');
813
+ .to.equal('UPDATE Animal SET UpdateDate = NOW(3), Deleted = 1, DeletingIDUser = @DeletingIDUser_2, DeleteDate = NOW(3) WHERE IDAnimal = @IDAnimal_w0 AND Animal.Deleted = @Deleted_w1;');
815
814
  }
816
815
  );
817
816
  test
@@ -834,7 +833,7 @@ suite
834
833
  // This is the query generated by the MSSQL dialect
835
834
  _Fable.log.trace('Delete Query', tmpQuery.query);
836
835
  Expect(tmpQuery.query.body)
837
- .to.equal('DELETE FROM `Animal` WHERE IDAnimal = :IDAnimal_w0;');
836
+ .to.equal('DELETE FROM Animal WHERE IDAnimal = @IDAnimal_w0;');
838
837
  }
839
838
  );
840
839
  test
@@ -854,7 +853,7 @@ suite
854
853
  // This is the query generated by the MSSQL dialect
855
854
  _Fable.log.trace('Undelete Query', tmpQuery.query);
856
855
  Expect(tmpQuery.query.body)
857
- .to.equal('UPDATE `Animal` SET UpdateDate = NOW(3), UpdatingIDUser = :UpdatingIDUser_1, Deleted = 0 WHERE IDAnimal = :IDAnimal_w0;');
856
+ .to.equal('UPDATE Animal SET UpdateDate = NOW(3), UpdatingIDUser = @UpdatingIDUser_1, Deleted = 0 WHERE IDAnimal = @IDAnimal_w0;');
858
857
  }
859
858
  );
860
859
  test
@@ -902,8 +901,7 @@ suite
902
901
  // This is the query generated by the MSSQL dialect
903
902
  _Fable.log.trace('Select Query', tmpQuery.query);
904
903
  Expect(tmpQuery.query.body)
905
- .to.equal('SELECT `Name`, `Age`, `Cost` FROM `Animal` INNER JOIN Test ON Test.IDAnimal = Animal.IDAnimal WHERE Age = :Age_w0 ORDER BY Age LIMIT 0, 10;');
906
- }
904
+ .to.equal('SELECT Name, Age, Cost FROM Animal INNER JOIN Test ON Test.IDAnimal = Animal.IDAnimal WHERE Age = @Age_w0 ORDER BY Age OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
907
905
  );
908
906
  test
909
907
  (
@@ -926,8 +924,7 @@ suite
926
924
  // This is the query generated by the MSSQL dialect
927
925
  _Fable.log.trace('Select Query', tmpQuery.query);
928
926
  Expect(tmpQuery.query.body)
929
- .to.equal('SELECT DISTINCT `Name`, `Age`, `Cost` FROM `Animal` INNER JOIN Test ON Test.IDAnimal = Animal.IDAnimal WHERE Age = :Age_w0 ORDER BY Age LIMIT 0, 10;');
930
- }
927
+ .to.equal('SELECT DISTINCT Name, Age, Cost FROM Animal INNER JOIN Test ON Test.IDAnimal = Animal.IDAnimal WHERE Age = @Age_w0 ORDER BY Age OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
931
928
  );
932
929
  test
933
930
  (
@@ -944,7 +941,7 @@ suite
944
941
  // This is the query generated by the MSSQL dialect
945
942
  _Fable.log.trace('Select Query', tmpQuery.query);
946
943
  Expect(tmpQuery.query.body)
947
- .to.equal('SELECT `Animal`.* FROM `Animal`;'); //bad join is ignored, warn log is generated
944
+ .to.equal('SELECT Animal.* FROM Animal;'); //bad join is ignored, warn log is generated
948
945
  }
949
946
  );
950
947
  }