foxhound 2.0.8 → 2.0.10

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.8",
3
+ "version": "2.0.10",
4
4
  "description": "A Database Query generation library.",
5
5
  "main": "source/FoxHound.js",
6
6
  "scripts": {
@@ -852,6 +852,19 @@ var FoxHound = function()
852
852
  enumerable: true
853
853
  });
854
854
 
855
+ /**
856
+ * Query
857
+ *
858
+ * @property query
859
+ * @type Object
860
+ */
861
+ Object.defineProperty(tmpNewFoxHoundObject, 'indexHints',
862
+ {
863
+ get: function() { return _Parameters.indexHints; },
864
+ set: function(pHints) { _Parameters.indexHints = pHints; },
865
+ enumerable: true,
866
+ });
867
+
855
868
  /**
856
869
  * Result
857
870
  *
@@ -78,7 +78,12 @@ var FoxHoundQueryParameters = (
78
78
  parameters: {}
79
79
  }
80
80
  */
81
-
81
+
82
+ indexHints: false,
83
+ /*
84
+ ['IndexName1', 'IndexName2'] // A list of index names to hint to the underlying provider, if supported
85
+ */
86
+
82
87
  // Who is making the query
83
88
  userID: 0,
84
89
 
@@ -93,4 +98,4 @@ var FoxHoundQueryParameters = (
93
98
  */
94
99
  });
95
100
 
96
- module.exports = FoxHoundQueryParameters;
101
+ module.exports = FoxHoundQueryParameters;
@@ -38,7 +38,7 @@ var FoxHoundDialectMSSQL = function(pFable)
38
38
  {
39
39
  pParameters.query.parameterTypes = {};
40
40
  }
41
- return ' '+pParameters.scope;
41
+ return ' ['+pParameters.scope+']';
42
42
  };
43
43
 
44
44
  var generateMSSQLParameterTypeEntry = function(pParameters, pColumnParameterName, pColumn)
@@ -152,7 +152,7 @@ var FoxHoundDialectMSSQL = function(pFable)
152
152
  // this means there is no autoincrementing unique ID column; treat as above
153
153
  return '';
154
154
  }
155
- const qualifiedIDColumn = `${tmpTableName}.${idColumn.Column}`;
155
+ const qualifiedIDColumn = `${idColumn.Column}`;
156
156
  return ` ${generateSafeFieldName(qualifiedIDColumn)}`;
157
157
  }
158
158
 
@@ -184,7 +184,15 @@ var FoxHoundDialectMSSQL = function(pFable)
184
184
  */
185
185
  var generateSafeFieldName = function(pFieldName)
186
186
  {
187
- return pFieldName;
187
+ // This isn't great but best we can do for MS SQL needing brackets around field names for reserved keywords
188
+ if ((pFieldName != '*') && (pFieldName.indexOf('[') < 0) && pFieldName.indexOf('.') < 0)
189
+ {
190
+ return '['+pFieldName+']';
191
+ }
192
+ else
193
+ {
194
+ return pFieldName;
195
+ }
188
196
  }
189
197
 
190
198
  /**
@@ -238,7 +246,7 @@ var FoxHoundDialectMSSQL = function(pFable)
238
246
  //if not, we need to add it
239
247
  tmpFilter.push(
240
248
  {
241
- Column: tmpTableName + '.' + tmpSchemaEntry.Column,
249
+ Column: tmpSchemaEntry.Column,
242
250
  Operator: '=',
243
251
  Value: 0,
244
252
  Connector: 'AND',
@@ -287,7 +295,7 @@ var FoxHoundDialectMSSQL = function(pFable)
287
295
  {
288
296
  tmpColumnParameter = tmpFilter[i].Parameter+'_w'+i;
289
297
  // Add the column name, operator and parameter name to the list of where value parenthetical
290
- tmpWhere += ' '+tmpFilter[i].Column+' '+tmpFilter[i].Operator+' ( @'+tmpColumnParameter+' )';
298
+ tmpWhere += ' ['+tmpFilter[i].Column+'] '+tmpFilter[i].Operator+' ( @'+tmpColumnParameter+' )';
291
299
  pParameters.query.parameters[tmpColumnParameter] = tmpFilter[i].Value;
292
300
  // Find the column in the schema
293
301
  generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpFilter[i].Parameter)
@@ -295,18 +303,18 @@ var FoxHoundDialectMSSQL = function(pFable)
295
303
  else if (tmpFilter[i].Operator === 'IS NULL')
296
304
  {
297
305
  // IS NULL is a special operator which doesn't require a value, or parameter
298
- tmpWhere += ' '+tmpFilter[i].Column+' '+tmpFilter[i].Operator;
306
+ tmpWhere += ' ['+tmpFilter[i].Column+'] '+tmpFilter[i].Operator;
299
307
  }
300
308
  else if (tmpFilter[i].Operator === 'IS NOT NULL')
301
309
  {
302
310
  // IS NOT NULL is a special operator which doesn't require a value, or parameter
303
- tmpWhere += ' '+tmpFilter[i].Column+' '+tmpFilter[i].Operator;
311
+ tmpWhere += ' ['+tmpFilter[i].Column+'] '+tmpFilter[i].Operator;
304
312
  }
305
313
  else
306
314
  {
307
315
  tmpColumnParameter = tmpFilter[i].Parameter+'_w'+i;
308
316
  // Add the column name, operator and parameter name to the list of where value parenthetical
309
- tmpWhere += ' '+tmpFilter[i].Column+' '+tmpFilter[i].Operator+' @'+tmpColumnParameter;
317
+ tmpWhere += ' ['+tmpFilter[i].Column+'] '+tmpFilter[i].Operator+' @'+tmpColumnParameter;
310
318
  pParameters.query.parameters[tmpColumnParameter] = tmpFilter[i].Value;
311
319
  generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpFilter[i].Parameter)
312
320
  }
@@ -340,7 +348,7 @@ var FoxHoundDialectMSSQL = function(pFable)
340
348
  {
341
349
  tmpOrderClause += ',';
342
350
  }
343
- tmpOrderClause += ' '+tmpOrderBy[i].Column;
351
+ tmpOrderClause += ' ['+tmpOrderBy[i].Column+']';
344
352
 
345
353
  if (tmpOrderBy[i].Direction == 'Descending')
346
354
  {
@@ -355,7 +363,7 @@ var FoxHoundDialectMSSQL = function(pFable)
355
363
  *
356
364
  * @method: generateLimit
357
365
  * @param: {Object} pParameters SQL Query Parameters
358
- * @return: {String} Returns the table name clause
366
+ * @return: {String} Returns the table limit clause
359
367
  */
360
368
  var generateLimit = function(pParameters)
361
369
  {
@@ -380,6 +388,23 @@ var FoxHoundDialectMSSQL = function(pFable)
380
388
  return tmpLimit;
381
389
  };
382
390
 
391
+ /**
392
+ * Generate the an index hinting clause
393
+ *
394
+ * @method: generateIndexHints
395
+ * @param: {Object} pParameters SQL Query Parameters
396
+ * @return: {String} Returns the table index hint clause
397
+ */
398
+ var generateIndexHints = function(pParameters)
399
+ {
400
+ if (!Array.isArray(pParameters.indexHints) || pParameters.indexHints.length < 1)
401
+ {
402
+ return '';
403
+ }
404
+
405
+ return ` WITH(INDEX(${pParameters.indexHints.join(',')}))`
406
+ };
407
+
383
408
  /**
384
409
  * Generate the join clause
385
410
  *
@@ -402,7 +427,7 @@ var FoxHoundDialectMSSQL = function(pFable)
402
427
  //verify that all required fields are valid
403
428
  if (join.Type && join.Table && join.From && join.To)
404
429
  {
405
- tmpJoinClause += ` ${join.Type} ${join.Table} ON ${join.From} = ${join.To}`;
430
+ tmpJoinClause += ` ${join.Type} [${join.Table}] ON ${join.From} = ${join.To}`;
406
431
  }
407
432
  }
408
433
 
@@ -477,20 +502,20 @@ var FoxHoundDialectMSSQL = function(pFable)
477
502
  {
478
503
  case 'UpdateDate':
479
504
  // This is an autoidentity, so we don't parameterize it and just pass in NULL
480
- tmpUpdate += ' '+tmpColumn+' = ' + SQL_NOW;
505
+ tmpUpdate += ' ['+tmpColumn+'] = ' + SQL_NOW;
481
506
  break;
482
507
  case 'UpdateIDUser':
483
508
  // This is the user ID, which we hope is in the query.
484
509
  // This is how to deal with a normal column
485
510
  var tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
486
- tmpUpdate += ' '+tmpColumn+' = @'+tmpColumnParameter;
511
+ tmpUpdate += ' ['+tmpColumn+'] = @'+tmpColumnParameter;
487
512
  // Set the query parameter
488
513
  pParameters.query.parameters[tmpColumnParameter] = pParameters.query.IDUser;
489
514
  generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpColumn)
490
515
  break;
491
516
  default:
492
517
  var tmpColumnDefaultParameter = tmpColumn+'_'+tmpCurrentColumn;
493
- tmpUpdate += ' '+tmpColumn+' = @'+tmpColumnDefaultParameter;
518
+ tmpUpdate += ' ['+tmpColumn+'] = @'+tmpColumnDefaultParameter;
494
519
 
495
520
  // Set the query parameter
496
521
  pParameters.query.parameters[tmpColumnDefaultParameter] = tmpRecords[0][tmpColumn];
@@ -544,21 +569,21 @@ var FoxHoundDialectMSSQL = function(pFable)
544
569
  switch (tmpSchemaEntry.Type)
545
570
  {
546
571
  case 'Deleted':
547
- tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = 1';
572
+ tmpUpdateSql = ' ['+tmpSchemaEntry.Column+'] = 1';
548
573
  tmpHasDeletedField = true; //this field is required in order for query to be built
549
574
  break;
550
575
  case 'DeleteDate':
551
- tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = ' + SQL_NOW;
576
+ tmpUpdateSql = ' ['+tmpSchemaEntry.Column+'] = ' + SQL_NOW;
552
577
  break;
553
578
  case 'UpdateDate':
554
579
  // Delete operation is an Update, so we should stamp the update time
555
- tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = ' + SQL_NOW;
580
+ tmpUpdateSql = ' ['+tmpSchemaEntry.Column+'] = ' + SQL_NOW;
556
581
  break;
557
582
  case 'DeleteIDUser':
558
583
  // This is the user ID, which we hope is in the query.
559
584
  // This is how to deal with a normal column
560
585
  var tmpColumnParameter = tmpSchemaEntry.Column+'_'+tmpCurrentColumn;
561
- tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = @'+tmpColumnParameter;
586
+ tmpUpdateSql = ' ['+tmpSchemaEntry.Column+'] = @'+tmpColumnParameter;
562
587
  // Set the query parameter
563
588
  pParameters.query.parameters[tmpColumnParameter] = pParameters.query.IDUser;
564
589
  generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpSchemaEntry)
@@ -617,16 +642,16 @@ var FoxHoundDialectMSSQL = function(pFable)
617
642
  switch (tmpSchemaEntry.Type)
618
643
  {
619
644
  case 'Deleted':
620
- tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = 0';
645
+ tmpUpdateSql = ' ['+tmpSchemaEntry.Column+'] = 0';
621
646
  tmpHasDeletedField = true; //this field is required in order for query to be built
622
647
  break;
623
648
  case 'UpdateDate':
624
649
  // The undelete operation is an Update, so we should stamp the update time
625
- tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = ' + SQL_NOW;
650
+ tmpUpdateSql = ' ['+tmpSchemaEntry.Column+'] = ' + SQL_NOW;
626
651
  break;
627
652
  case 'UpdateIDUser':
628
653
  var tmpColumnParameter = tmpSchemaEntry.Column+'_'+tmpCurrentColumn;
629
- tmpUpdateSql = ' '+tmpSchemaEntry.Column+' = @'+tmpColumnParameter;
654
+ tmpUpdateSql = ' ['+tmpSchemaEntry.Column+'] = @'+tmpColumnParameter;
630
655
  pParameters.query.parameters[tmpColumnParameter] = pParameters.query.IDUser;
631
656
  generateMSSQLParameterTypeEntry(pParameters, tmpColumnParameter, tmpSchemaEntry)
632
657
  break;
@@ -855,7 +880,7 @@ var FoxHoundDialectMSSQL = function(pFable)
855
880
  {
856
881
  tmpCreateSet += ',';
857
882
  }
858
- tmpCreateSet += ' '+tmpColumn;
883
+ tmpCreateSet += ' ['+tmpColumn+']';
859
884
  }
860
885
  continue;
861
886
  default:
@@ -863,7 +888,7 @@ var FoxHoundDialectMSSQL = function(pFable)
863
888
  {
864
889
  tmpCreateSet += ',';
865
890
  }
866
- tmpCreateSet += ' '+tmpColumn;
891
+ tmpCreateSet += ' ['+tmpColumn+']';
867
892
  break;
868
893
  }
869
894
  }
@@ -909,6 +934,7 @@ var FoxHoundDialectMSSQL = function(pFable)
909
934
  var tmpJoin = generateJoins(pParameters);
910
935
  var tmpOrderBy = generateOrderBy(pParameters);
911
936
  var tmpLimit = generateLimit(pParameters);
937
+ var tmpIndexHints = generateIndexHints(pParameters);
912
938
  const tmpOptDistinct = pParameters.distinct ? ' DISTINCT' : '';
913
939
 
914
940
  if (pParameters.queryOverride)
@@ -916,7 +942,7 @@ var FoxHoundDialectMSSQL = function(pFable)
916
942
  try
917
943
  {
918
944
  var tmpQueryTemplate = _Fable.Utility.template(pParameters.queryOverride);
919
- return tmpQueryTemplate({FieldList:tmpFieldList, TableName:tmpTableName, Where:tmpWhere, Join:tmpJoin, OrderBy:tmpOrderBy, Limit:tmpLimit, Distinct: tmpOptDistinct, _Params: pParameters});
945
+ return tmpQueryTemplate({FieldList:tmpFieldList, TableName:tmpTableName, Where:tmpWhere, Join:tmpJoin, OrderBy:tmpOrderBy, Limit:tmpLimit, IndexHints: tmpIndexHints, Distinct: tmpOptDistinct, _Params: pParameters});
920
946
  }
921
947
  catch (pError)
922
948
  {
@@ -926,7 +952,7 @@ var FoxHoundDialectMSSQL = function(pFable)
926
952
  }
927
953
  }
928
954
 
929
- return `SELECT${tmpOptDistinct}${tmpFieldList} FROM${tmpTableName}${tmpJoin}${tmpWhere}${tmpOrderBy}${tmpLimit};`;
955
+ return `SELECT${tmpOptDistinct}${tmpFieldList} FROM${tmpTableName}${tmpIndexHints}${tmpJoin}${tmpWhere}${tmpOrderBy}${tmpLimit};`;
930
956
  };
931
957
 
932
958
  var Update = function(pParameters)
@@ -989,6 +1015,7 @@ var FoxHoundDialectMSSQL = function(pFable)
989
1015
  var tmpTableName = generateTableName(pParameters);
990
1016
  var tmpJoin = generateJoins(pParameters);
991
1017
  var tmpWhere = generateWhere(pParameters);
1018
+ var tmpIndexHints = generateIndexHints(pParameters);
992
1019
  // here, we ignore the distinct keyword if no fields have been specified and
993
1020
  if (pParameters.distinct && tmpFieldList.length < 1)
994
1021
  {
@@ -1001,7 +1028,7 @@ var FoxHoundDialectMSSQL = function(pFable)
1001
1028
  try
1002
1029
  {
1003
1030
  var tmpQueryTemplate = _Fable.Utility.template(pParameters.queryOverride);
1004
- return tmpQueryTemplate({FieldList:[], TableName:tmpTableName, Where:tmpWhere, OrderBy:'', Limit:'', Distinct: tmpOptDistinct, _Params: pParameters});
1031
+ return tmpQueryTemplate({FieldList:[], TableName:tmpTableName, Where:tmpWhere, OrderBy:'', IndexHints: tmpIndexHints, Limit:'', Distinct: tmpOptDistinct, _Params: pParameters});
1005
1032
  }
1006
1033
  catch (pError)
1007
1034
  {
@@ -1011,7 +1038,7 @@ var FoxHoundDialectMSSQL = function(pFable)
1011
1038
  }
1012
1039
  }
1013
1040
 
1014
- return `SELECT COUNT(${tmpOptDistinct}${tmpFieldList || '*'}) AS Row_Count FROM${tmpTableName}${tmpJoin}${tmpWhere};`;
1041
+ return `SELECT COUNT(${tmpOptDistinct}${tmpFieldList || '*'}) AS Row_Count FROM${tmpTableName}${tmpIndexHints}${tmpJoin}${tmpWhere};`;
1015
1042
  };
1016
1043
 
1017
1044
  var tmpDialect = ({
@@ -296,7 +296,7 @@ var FoxHoundDialectMySQL = function(pFable)
296
296
  *
297
297
  * @method: generateLimit
298
298
  * @param: {Object} pParameters SQL Query Parameters
299
- * @return: {String} Returns the table name clause
299
+ * @return: {String} Returns the table limit clause
300
300
  */
301
301
  var generateLimit = function(pParameters)
302
302
  {
@@ -317,6 +317,23 @@ var FoxHoundDialectMySQL = function(pFable)
317
317
  return tmpLimit;
318
318
  };
319
319
 
320
+ /**
321
+ * Generate the use index clause
322
+ *
323
+ * @method: generateIndexHints
324
+ * @param: {Object} pParameters SQL Query Parameters
325
+ * @return: {String} Returns the table limit clause
326
+ */
327
+ var generateIndexHints = function(pParameters)
328
+ {
329
+ if (!Array.isArray(pParameters.indexHints) || pParameters.indexHints.length < 1)
330
+ {
331
+ return '';
332
+ }
333
+
334
+ return ` USE INDEX (${pParameters.indexHints.join(',')})`;
335
+ };
336
+
320
337
  /**
321
338
  * Generate the join clause
322
339
  *
@@ -827,6 +844,7 @@ var FoxHoundDialectMySQL = function(pFable)
827
844
  var tmpJoin = generateJoins(pParameters);
828
845
  var tmpOrderBy = generateOrderBy(pParameters);
829
846
  var tmpLimit = generateLimit(pParameters);
847
+ var tmpIndexHints = generateIndexHints(pParameters);
830
848
  const tmpOptDistinct = pParameters.distinct ? ' DISTINCT' : '';
831
849
 
832
850
  if (pParameters.queryOverride)
@@ -834,7 +852,7 @@ var FoxHoundDialectMySQL = function(pFable)
834
852
  try
835
853
  {
836
854
  var tmpQueryTemplate = _Fable.Utility.template(pParameters.queryOverride);
837
- return tmpQueryTemplate({FieldList:tmpFieldList, TableName:tmpTableName, Where:tmpWhere, Join:tmpJoin, OrderBy:tmpOrderBy, Limit:tmpLimit, Distinct: tmpOptDistinct, _Params: pParameters});
855
+ return tmpQueryTemplate({FieldList:tmpFieldList, TableName:tmpTableName, Where:tmpWhere, Join:tmpJoin, OrderBy:tmpOrderBy, Limit:tmpLimit, IndexHints: tmpIndexHints, Distinct: tmpOptDistinct, _Params: pParameters});
838
856
  }
839
857
  catch (pError)
840
858
  {
@@ -844,7 +862,7 @@ var FoxHoundDialectMySQL = function(pFable)
844
862
  }
845
863
  }
846
864
 
847
- return `SELECT${tmpOptDistinct}${tmpFieldList} FROM${tmpTableName}${tmpJoin}${tmpWhere}${tmpOrderBy}${tmpLimit};`;
865
+ return `SELECT${tmpOptDistinct}${tmpFieldList} FROM${tmpTableName}${tmpIndexHints}${tmpJoin}${tmpWhere}${tmpOrderBy}${tmpLimit};`;
848
866
  };
849
867
 
850
868
  var Update = function(pParameters)
@@ -907,6 +925,7 @@ var FoxHoundDialectMySQL = function(pFable)
907
925
  var tmpTableName = generateTableName(pParameters);
908
926
  var tmpJoin = generateJoins(pParameters);
909
927
  var tmpWhere = generateWhere(pParameters);
928
+ var tmpIndexHints = generateIndexHints(pParameters);
910
929
  // here, we ignore the distinct keyword if no fields have been specified and
911
930
  if (pParameters.distinct && tmpFieldList.length < 1)
912
931
  {
@@ -919,7 +938,7 @@ var FoxHoundDialectMySQL = function(pFable)
919
938
  try
920
939
  {
921
940
  var tmpQueryTemplate = _Fable.Utility.template(pParameters.queryOverride);
922
- return tmpQueryTemplate({FieldList:[], TableName:tmpTableName, Where:tmpWhere, OrderBy:'', Limit:'', Distinct: tmpOptDistinct, _Params: pParameters});
941
+ return tmpQueryTemplate({FieldList:[], TableName:tmpTableName, Where:tmpWhere, OrderBy:'', Limit:'', IndexHints: tmpIndexHints, Distinct: tmpOptDistinct, _Params: pParameters});
923
942
  }
924
943
  catch (pError)
925
944
  {
@@ -929,7 +948,7 @@ var FoxHoundDialectMySQL = function(pFable)
929
948
  }
930
949
  }
931
950
 
932
- return `SELECT COUNT(${tmpOptDistinct}${tmpFieldList || '*'}) AS RowCount FROM${tmpTableName}${tmpJoin}${tmpWhere};`;
951
+ return `SELECT COUNT(${tmpOptDistinct}${tmpFieldList || '*'}) AS RowCount FROM${tmpTableName}${tmpIndexHints}${tmpJoin}${tmpWhere};`;
933
952
  };
934
953
 
935
954
  var tmpDialect = ({
@@ -124,6 +124,22 @@ suite
124
124
  }
125
125
  );
126
126
  test
127
+ (
128
+ 'Read Query with Index Hints',
129
+ function()
130
+ {
131
+ var tmpQuery = libFoxHound.new(_Fable).setDialect('MySQL').setScope('Animal');
132
+ tmpQuery.addSort({Column:'Cost',Direction:'Descending'});
133
+ tmpQuery.indexHints = ['AnimalIndex_1', 'AnimalIndex_2'];
134
+ // Build the query
135
+ tmpQuery.buildReadQuery();
136
+ // This is the query generated by the MySQL dialect
137
+ _Fable.log.trace('Simple Select Query', tmpQuery.query);
138
+ Expect(tmpQuery.query.body)
139
+ .to.equal('SELECT `Animal`.* FROM `Animal` USE INDEX (AnimalIndex_1,AnimalIndex_2) ORDER BY Cost DESC;');
140
+ }
141
+ );
142
+ test
127
143
  (
128
144
  'Read Query with Distinct',
129
145
  function()
@@ -244,14 +260,15 @@ suite
244
260
  .setDataElements(['Name', 'Age', 'Cost'])
245
261
  .setSort([{Column:'Age',Direction:'Ascending'},{Column:'Cost',Direction:'Descending'}])
246
262
  .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
263
+ tmpQuery.indexHints = ['AnimalIndex_1', 'AnimalIndex_2'];
247
264
  tmpQuery.parameters.CustomFields = 'Name, Age * 5, Cost';
248
- tmpQuery.parameters.queryOverride = 'SELECT <%= _Params.CustomFields %> FROM <%= TableName %> <%= Where %> <%= Limit %>;';
265
+ tmpQuery.parameters.queryOverride = 'SELECT <%= _Params.CustomFields %> FROM <%= TableName %><%= IndexHints %> <%= Where %> <%= Limit %>;';
249
266
  // Build the query
250
267
  tmpQuery.buildReadQuery();
251
268
  // This is the query generated by the MySQL dialect
252
269
  _Fable.log.trace('Custom Select Query', tmpQuery.query);
253
270
  Expect(tmpQuery.query.body)
254
- .to.equal('SELECT Name, Age * 5, Cost FROM `Animal` WHERE Age = :Age_w0 LIMIT 0, 10;');
271
+ .to.equal('SELECT Name, Age * 5, Cost FROM `Animal` USE INDEX (AnimalIndex_1,AnimalIndex_2) WHERE Age = :Age_w0 LIMIT 0, 10;');
255
272
  }
256
273
  );
257
274
  test
@@ -303,13 +320,14 @@ suite
303
320
  .setDialect('MySQL')
304
321
  .setScope('Animal')
305
322
  .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
306
- tmpQuery.parameters.queryOverride = 'SELECT COUNT(*) AS RowCount FROM <%= TableName %> <%= Where %>;';
323
+ tmpQuery.indexHints = ['AnimalIndex_1', 'AnimalIndex_2'];
324
+ tmpQuery.parameters.queryOverride = 'SELECT COUNT(*) AS RowCount FROM <%= TableName %><%= IndexHints %> <%= Where %>;';
307
325
  // Build the query
308
326
  tmpQuery.buildCountQuery();
309
327
  // This is the query generated by the MySQL dialect
310
328
  _Fable.log.trace('Custom Count Query', tmpQuery.query);
311
329
  Expect(tmpQuery.query.body)
312
- .to.equal('SELECT COUNT(*) AS RowCount FROM `Animal` WHERE Age = :Age_w0;');
330
+ .to.equal('SELECT COUNT(*) AS RowCount FROM `Animal` USE INDEX (AnimalIndex_1,AnimalIndex_2) WHERE Age = :Age_w0;');
313
331
  }
314
332
  );
315
333
  test
@@ -91,7 +91,7 @@ suite
91
91
  // This is the query generated by the MSSQL dialect
92
92
  _Fable.log.trace('Create Query', tmpQuery.query);
93
93
  Expect(tmpQuery.query.body)
94
- .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);");
95
95
  }
96
96
  );
97
97
  test
@@ -122,7 +122,23 @@ suite
122
122
  // This is the query generated by the MSSQL dialect
123
123
  _Fable.log.trace('Simple Select Query', tmpQuery.query);
124
124
  Expect(tmpQuery.query.body)
125
- .to.equal('SELECT Animal.* FROM Animal ORDER BY Cost DESC;');
125
+ .to.equal('SELECT [Animal].* FROM [Animal] ORDER BY [Cost] DESC;');
126
+ }
127
+ );
128
+ test
129
+ (
130
+ 'Read Query with Index Hinting',
131
+ function()
132
+ {
133
+ var tmpQuery = libFoxHound.new(_Fable).setDialect('MSSQL').setScope('Animal');
134
+ tmpQuery.addSort({Column:'Cost',Direction:'Descending'});
135
+ tmpQuery.indexHints = ['AnimalIndex_1'];
136
+ // Build the query
137
+ tmpQuery.buildReadQuery();
138
+ // This is the query generated by the MSSQL dialect
139
+ _Fable.log.trace('Simple Select Query', tmpQuery.query);
140
+ Expect(tmpQuery.query.body)
141
+ .to.equal('SELECT [Animal].* FROM [Animal] WITH(INDEX(AnimalIndex_1)) ORDER BY [Cost] DESC;');
126
142
  }
127
143
  );
128
144
  test
@@ -138,7 +154,7 @@ suite
138
154
  // This is the query generated by the MSSQL dialect
139
155
  _Fable.log.trace('Simple Select Query', tmpQuery.query);
140
156
  Expect(tmpQuery.query.body)
141
- .to.equal('SELECT DISTINCT Animal.* FROM Animal ORDER BY Cost DESC;');
157
+ .to.equal('SELECT DISTINCT [Animal].* FROM [Animal] ORDER BY [Cost] DESC;');
142
158
  }
143
159
  );
144
160
  test
@@ -160,7 +176,7 @@ suite
160
176
  // This is the query generated by the MSSQL dialect
161
177
  _Fable.log.trace('Select Query', tmpQuery.query);
162
178
  Expect(tmpQuery.query.body)
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;'); }
179
+ .to.equal('SELECT [Name], [Age], [Cost] FROM [Animal] WHERE [Age] = @Age_w0 ORDER BY [Age], [Cost] OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
164
180
  );
165
181
  test
166
182
  (
@@ -172,7 +188,7 @@ suite
172
188
  .setScope('Animal')
173
189
  .setCap(10)
174
190
  .setBegin(0)
175
- .setDataElements(['*', 'Name', 'Age', 'Cost', 'Animal.*'])
191
+ .setDataElements(['*', 'Name', 'Age', 'Cost', '[Animal].*'])
176
192
  .setSort([{Column:'Age',Direction:'Ascending'}])
177
193
  .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
178
194
  tmpQuery.addSort('Cost');
@@ -181,7 +197,7 @@ suite
181
197
  // This is the query generated by the MSSQL dialect
182
198
  _Fable.log.trace('Select Query', tmpQuery.query);
183
199
  Expect(tmpQuery.query.body)
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;'); }
200
+ .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
201
  );
186
202
  test
187
203
  (
@@ -206,7 +222,7 @@ suite
206
222
  // This is the query generated by the MSSQL dialect
207
223
  _Fable.log.trace('Select Query', tmpQuery.query);
208
224
  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 OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
225
+ .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
226
  }
211
227
  );
212
228
  test
@@ -228,7 +244,7 @@ suite
228
244
  // This is the query generated by the MSSQL dialect
229
245
  _Fable.log.trace('Custom Select Query', tmpQuery.query);
230
246
  Expect(tmpQuery.query.body)
231
- .to.equal('SELECT Name, Age * 5, Cost FROM Animal WHERE Age = @Age_w0 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
247
+ .to.equal('SELECT Name, Age * 5, Cost FROM [Animal] WHERE [Age] = @Age_w0 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
232
248
  );
233
249
  test
234
250
  (
@@ -250,7 +266,7 @@ suite
250
266
  // This is the query generated by the MSSQL dialect
251
267
  _Fable.log.trace('Custom Select Query', tmpQuery.query);
252
268
  Expect(tmpQuery.query.body)
253
- .to.equal('SELECT Name, Age * 5, Cost FROM Animal WHERE Age = @Age_w0 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
269
+ .to.equal('SELECT Name, Age * 5, Cost FROM [Animal] WHERE [Age] = @Age_w0 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;'); }
254
270
  );
255
271
  test
256
272
  (
@@ -301,13 +317,32 @@ suite
301
317
  .setDialect('MSSQL')
302
318
  .setScope('Animal')
303
319
  .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
304
- tmpQuery.parameters.queryOverride = 'SELECT COUNT(*) AS RowCount FROM <%= TableName %> <%= Where %>;';
320
+ tmpQuery.parameters.queryOverride = 'SELECT COUNT(*) AS RowCount FROM <%= TableName %><%= IndexHints %> <%= Where %>;';
321
+ // Build the query
322
+ tmpQuery.buildCountQuery();
323
+ // This is the query generated by the MSSQL dialect
324
+ _Fable.log.trace('Custom Count Query', tmpQuery.query);
325
+ Expect(tmpQuery.query.body)
326
+ .to.equal('SELECT COUNT(*) AS RowCount FROM [Animal] WHERE [Age] = @Age_w0;');
327
+ }
328
+ );
329
+ test
330
+ (
331
+ 'Custom Count Query with Index Hinting',
332
+ function()
333
+ {
334
+ var tmpQuery = libFoxHound.new(_Fable)
335
+ .setDialect('MSSQL')
336
+ .setScope('Animal')
337
+ .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
338
+ tmpQuery.indexHints = ['AnimalIndex_1'];
339
+ tmpQuery.parameters.queryOverride = 'SELECT COUNT(*) AS RowCount FROM <%= TableName %><%= IndexHints %> <%= Where %>;';
305
340
  // Build the query
306
341
  tmpQuery.buildCountQuery();
307
342
  // This is the query generated by the MSSQL dialect
308
343
  _Fable.log.trace('Custom Count Query', tmpQuery.query);
309
344
  Expect(tmpQuery.query.body)
310
- .to.equal('SELECT COUNT(*) AS RowCount FROM Animal WHERE Age = @Age_w0;');
345
+ .to.equal('SELECT COUNT(*) AS RowCount FROM [Animal] WITH(INDEX(AnimalIndex_1)) WHERE [Age] = @Age_w0;');
311
346
  }
312
347
  );
313
348
  test
@@ -326,7 +361,7 @@ suite
326
361
  // This is the query generated by the MSSQL dialect
327
362
  _Fable.log.trace('Custom Count Query', tmpQuery.query);
328
363
  Expect(tmpQuery.query.body)
329
- .to.equal('SELECT COUNT(*) AS RowCount FROM Animal WHERE Age = @Age_w0;');
364
+ .to.equal('SELECT COUNT(*) AS RowCount FROM [Animal] WHERE [Age] = @Age_w0;');
330
365
  }
331
366
  );
332
367
  test
@@ -345,7 +380,7 @@ suite
345
380
  // This is the query generated by the MSSQL dialect
346
381
  _Fable.log.trace('Update Query', tmpQuery.query);
347
382
  Expect(tmpQuery.query.body)
348
- .to.equal('UPDATE Animal SET Age = @Age_0, Color = @Color_1 WHERE IDAnimal = @IDAnimal_w0;');
383
+ .to.equal('UPDATE [Animal] SET [Age] = @Age_0, [Color] = @Color_1 WHERE [IDAnimal] = @IDAnimal_w0;');
349
384
  }
350
385
  );
351
386
  test
@@ -379,7 +414,7 @@ suite
379
414
  // This is the query generated by the MSSQL dialect
380
415
  _Fable.log.trace('Delete Query', tmpQuery.query);
381
416
  Expect(tmpQuery.query.body)
382
- .to.equal('DELETE FROM Animal WHERE IDAnimal = @IDAnimal_w0;');
417
+ .to.equal('DELETE FROM [Animal] WHERE [IDAnimal] = @IDAnimal_w0;');
383
418
  }
384
419
  );
385
420
  test
@@ -390,13 +425,14 @@ suite
390
425
  var tmpQuery = libFoxHound.new(_Fable)
391
426
  .setDialect('MSSQL')
392
427
  .setScope('Animal');
428
+ tmpQuery.indexHints = ['AnimalIndex_1'];
393
429
 
394
430
  // Build the query
395
431
  tmpQuery.buildCountQuery();
396
432
  // This is the query generated by the MSSQL dialect
397
433
  _Fable.log.trace('Count Query', tmpQuery.query);
398
434
  Expect(tmpQuery.query.body)
399
- .to.equal('SELECT COUNT(*) AS Row_Count FROM Animal;');
435
+ .to.equal('SELECT COUNT(*) AS Row_Count FROM [Animal] WITH(INDEX(AnimalIndex_1));');
400
436
  }
401
437
  );
402
438
  test
@@ -416,7 +452,7 @@ suite
416
452
  _Fable.log.trace('Count Distinct Query', tmpQuery.query);
417
453
  Expect(tmpQuery.query.body)
418
454
  // 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;');
455
+ .to.equal('SELECT COUNT(DISTINCT [IDAnimal]) AS Row_Count FROM [Animal] WHERE [Deleted] = @Deleted_w0;');
420
456
  }
421
457
  );
422
458
  test
@@ -434,7 +470,7 @@ suite
434
470
  // This is the query generated by the MSSQL dialect
435
471
  _Fable.log.trace('Count Distinct Query', tmpQuery.query);
436
472
  Expect(tmpQuery.query.body)
437
- .to.equal('SELECT COUNT(*) AS Row_Count FROM Animal;');
473
+ .to.equal('SELECT COUNT(*) AS Row_Count FROM [Animal];');
438
474
  }
439
475
  );
440
476
  test
@@ -453,7 +489,7 @@ suite
453
489
  // This is the query generated by the MSSQL dialect
454
490
  _Fable.log.trace('Count Distinct Query', tmpQuery.query);
455
491
  Expect(tmpQuery.query.body)
456
- .to.equal('SELECT COUNT(DISTINCT Name) AS Row_Count FROM Animal;');
492
+ .to.equal('SELECT COUNT(DISTINCT [Name]) AS Row_Count FROM [Animal];');
457
493
  }
458
494
  );
459
495
  }
@@ -493,7 +529,7 @@ suite
493
529
  // This is the query generated by the MSSQL dialect
494
530
  _Fable.log.trace('Create Query', tmpQuery.query);
495
531
  Expect(tmpQuery.query.body)
496
- .to.equal("INSERT INTO Animal ( GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, Name, Age) VALUES ( @GUIDAnimal_1, GETUTCDATE(), @CreatingIDUser_3, GETUTCDATE(), @UpdatingIDUser_5, @Deleted_6, @Name_7, @Age_8);");
532
+ .to.equal("INSERT INTO [Animal] ( [GUIDAnimal], [CreateDate], [CreatingIDUser], [UpdateDate], [UpdatingIDUser], [Deleted], [Name], [Age]) VALUES ( @GUIDAnimal_1, GETUTCDATE(), @CreatingIDUser_3, GETUTCDATE(), @UpdatingIDUser_5, @Deleted_6, @Name_7, @Age_8);");
497
533
  }
498
534
  );
499
535
  test
@@ -525,7 +561,7 @@ suite
525
561
  // This is the query generated by the MSSQL dialect
526
562
  _Fable.log.trace('Create Query', tmpQuery.query);
527
563
  Expect(tmpQuery.query.body)
528
- .to.equal("INSERT INTO Animal ( GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, Name, Age) VALUES ( @GUIDAnimal_1, GETUTCDATE(), @CreatingIDUser_3, GETUTCDATE(), @UpdatingIDUser_5, @Deleted_6, @Name_7, @Age_8);");
564
+ .to.equal("INSERT INTO [Animal] ( [GUIDAnimal], [CreateDate], [CreatingIDUser], [UpdateDate], [UpdatingIDUser], [Deleted], [Name], [Age]) VALUES ( @GUIDAnimal_1, GETUTCDATE(), @CreatingIDUser_3, GETUTCDATE(), @UpdatingIDUser_5, @Deleted_6, @Name_7, @Age_8);");
529
565
  }
530
566
  );
531
567
  test
@@ -561,7 +597,7 @@ suite
561
597
  // This is the query generated by the MSSQL dialect
562
598
  _Fable.log.trace('Create Query (AutoIdentity disabled)', tmpQuery.query);
563
599
  Expect(tmpQuery.query.body)
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);");
600
+ .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);");
565
601
  }
566
602
  );
567
603
  test
@@ -582,7 +618,7 @@ suite
582
618
  // This is the query generated by the MSSQL dialect
583
619
  _Fable.log.trace('Select Query', tmpQuery.query);
584
620
  Expect(tmpQuery.query.body)
585
- .to.equal('SELECT Name, Age, Cost FROM Animal WHERE Animal.Deleted = @Deleted_w0 OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
621
+ .to.equal('SELECT [Name], [Age], [Cost] FROM [Animal] WHERE [Deleted] = @Deleted_w0 OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
586
622
  }
587
623
  );
588
624
  test
@@ -604,7 +640,7 @@ suite
604
640
  // This is the query generated by the MSSQL dialect
605
641
  _Fable.log.trace('Select Query', tmpQuery.query);
606
642
  Expect(tmpQuery.query.body)
607
- .to.equal('SELECT DISTINCT Name, Age, Cost FROM Animal WHERE Animal.Deleted = @Deleted_w0 OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
643
+ .to.equal('SELECT DISTINCT [Name], [Age], [Cost] FROM [Animal] WHERE [Deleted] = @Deleted_w0 OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
608
644
  }
609
645
  );
610
646
  test
@@ -633,7 +669,7 @@ suite
633
669
  // This is the query generated by the MSSQL dialect
634
670
  _Fable.log.trace('Select Query', tmpQuery.query);
635
671
  Expect(tmpQuery.query.body)
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;');
672
+ .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;');
637
673
  }
638
674
  );
639
675
  test
@@ -655,7 +691,7 @@ suite
655
691
  // This is the query generated by the MSSQL dialect
656
692
  _Fable.log.trace('Select Query', tmpQuery.query);
657
693
  Expect(tmpQuery.query.body)
658
- .to.equal('SELECT Name, Age, Cost FROM Animal OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
694
+ .to.equal('SELECT [Name], [Age], [Cost] FROM [Animal] OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;');
659
695
  }
660
696
  );
661
697
  test
@@ -676,7 +712,7 @@ suite
676
712
  // This is the query generated by the MSSQL dialect
677
713
  _Fable.log.trace('Delete Query', tmpQuery.query);
678
714
  Expect(tmpQuery.query.body)
679
- .to.equal('UPDATE Animal SET UpdateDate = GETUTCDATE(), Deleted = 1, DeletingIDUser = @DeletingIDUser_2, DeleteDate = GETUTCDATE() WHERE IDAnimal = @IDAnimal_w0 AND Animal.Deleted = @Deleted_w1;');
715
+ .to.equal('UPDATE [Animal] SET [UpdateDate] = GETUTCDATE(), [Deleted] = 1, [DeletingIDUser] = @DeletingIDUser_2, [DeleteDate] = GETUTCDATE() WHERE [IDAnimal] = @IDAnimal_w0 AND [Deleted] = @Deleted_w1;');
680
716
  }
681
717
  );
682
718
  test
@@ -704,7 +740,7 @@ suite
704
740
  // This is the query generated by the MSSQL dialect
705
741
  _Fable.log.trace('Update Query', tmpQuery.query);
706
742
  Expect(tmpQuery.query.body)
707
- .to.equal('UPDATE Animal SET GUIDAnimal = @GUIDAnimal_0, UpdateDate = GETUTCDATE(), UpdatingIDUser = @UpdatingIDUser_2, Name = @Name_3, Age = @Age_4 WHERE IDAnimal = @IDAnimal_w0;');
743
+ .to.equal('UPDATE [Animal] SET [GUIDAnimal] = @GUIDAnimal_0, [UpdateDate] = GETUTCDATE(), [UpdatingIDUser] = @UpdatingIDUser_2, [Name] = @Name_3, [Age] = @Age_4 WHERE [IDAnimal] = @IDAnimal_w0;');
708
744
  }
709
745
  );
710
746
  test
@@ -734,7 +770,7 @@ suite
734
770
  // This is the query generated by the MSSQL dialect
735
771
  _Fable.log.trace('Update Query', tmpQuery.query);
736
772
  Expect(tmpQuery.query.body)
737
- .to.equal('UPDATE Animal SET GUIDAnimal = @GUIDAnimal_0, Name = @Name_1, Age = @Age_2 WHERE IDAnimal = @IDAnimal_w0;');
773
+ .to.equal('UPDATE [Animal] SET [GUIDAnimal] = @GUIDAnimal_0, [Name] = @Name_1, [Age] = @Age_2 WHERE [IDAnimal] = @IDAnimal_w0;');
738
774
  }
739
775
  );
740
776
  test
@@ -756,7 +792,7 @@ suite
756
792
  // This is the query generated by the MSSQL dialect
757
793
  _Fable.log.trace('Delete Query', tmpQuery.query);
758
794
  Expect(tmpQuery.query.body)
759
- .to.equal('DELETE FROM Animal WHERE IDAnimal = @IDAnimal_w0;');
795
+ .to.equal('DELETE FROM [Animal] WHERE [IDAnimal] = @IDAnimal_w0;');
760
796
  }
761
797
  );
762
798
  test
@@ -788,7 +824,7 @@ suite
788
824
  // This is the query generated by the MSSQL dialect
789
825
  _Fable.log.trace('Update Query', tmpQuery.query);
790
826
  Expect(tmpQuery.query.body)
791
- .to.equal('UPDATE Animal SET GUIDAnimal = @GUIDAnimal_0, UpdateDate = GETUTCDATE(), UpdatingIDUser = @UpdatingIDUser_2, Deleted = @Deleted_3, Name = @Name_4, Age = @Age_5 WHERE IDAnimal = @IDAnimal_w0 AND Deleted = @Deleted_w1;');
827
+ .to.equal('UPDATE [Animal] SET [GUIDAnimal] = @GUIDAnimal_0, [UpdateDate] = GETUTCDATE(), [UpdatingIDUser] = @UpdatingIDUser_2, [Deleted] = @Deleted_3, [Name] = @Name_4, [Age] = @Age_5 WHERE [IDAnimal] = @IDAnimal_w0 AND [Deleted] = @Deleted_w1;');
792
828
  }
793
829
  );
794
830
  test
@@ -810,7 +846,7 @@ suite
810
846
  // This is the query generated by the MSSQL dialect
811
847
  _Fable.log.trace('Delete Query', tmpQuery.query);
812
848
  Expect(tmpQuery.query.body)
813
- .to.equal('UPDATE Animal SET UpdateDate = GETUTCDATE(), Deleted = 1, DeletingIDUser = @DeletingIDUser_2, DeleteDate = GETUTCDATE() WHERE IDAnimal = @IDAnimal_w0 AND Animal.Deleted = @Deleted_w1;');
849
+ .to.equal('UPDATE [Animal] SET [UpdateDate] = GETUTCDATE(), [Deleted] = 1, [DeletingIDUser] = @DeletingIDUser_2, [DeleteDate] = GETUTCDATE() WHERE [IDAnimal] = @IDAnimal_w0 AND [Deleted] = @Deleted_w1;');
814
850
  }
815
851
  );
816
852
  test
@@ -833,7 +869,7 @@ suite
833
869
  // This is the query generated by the MSSQL dialect
834
870
  _Fable.log.trace('Delete Query', tmpQuery.query);
835
871
  Expect(tmpQuery.query.body)
836
- .to.equal('DELETE FROM Animal WHERE IDAnimal = @IDAnimal_w0;');
872
+ .to.equal('DELETE FROM [Animal] WHERE [IDAnimal] = @IDAnimal_w0;');
837
873
  }
838
874
  );
839
875
  test
@@ -853,7 +889,7 @@ suite
853
889
  // This is the query generated by the MSSQL dialect
854
890
  _Fable.log.trace('Undelete Query', tmpQuery.query);
855
891
  Expect(tmpQuery.query.body)
856
- .to.equal('UPDATE Animal SET UpdateDate = GETUTCDATE(), UpdatingIDUser = @UpdatingIDUser_1, Deleted = 0 WHERE IDAnimal = @IDAnimal_w0;');
892
+ .to.equal('UPDATE [Animal] SET [UpdateDate] = GETUTCDATE(), [UpdatingIDUser] = @UpdatingIDUser_1, [Deleted] = 0 WHERE [IDAnimal] = @IDAnimal_w0;');
857
893
  }
858
894
  );
859
895
  test
@@ -901,7 +937,7 @@ suite
901
937
  // This is the query generated by the MSSQL dialect
902
938
  _Fable.log.trace('Select Query', tmpQuery.query);
903
939
  Expect(tmpQuery.query.body)
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;'); }
940
+ .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;'); }
905
941
  );
906
942
  test
907
943
  (
@@ -924,7 +960,7 @@ suite
924
960
  // This is the query generated by the MSSQL dialect
925
961
  _Fable.log.trace('Select Query', tmpQuery.query);
926
962
  Expect(tmpQuery.query.body)
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;'); }
963
+ .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;'); }
928
964
  );
929
965
  test
930
966
  (
@@ -941,7 +977,7 @@ suite
941
977
  // This is the query generated by the MSSQL dialect
942
978
  _Fable.log.trace('Select Query', tmpQuery.query);
943
979
  Expect(tmpQuery.query.body)
944
- .to.equal('SELECT Animal.* FROM Animal;'); //bad join is ignored, warn log is generated
980
+ .to.equal('SELECT [Animal].* FROM [Animal];'); //bad join is ignored, warn log is generated
945
981
  }
946
982
  );
947
983
  }