@oino-ts/db-mssql 0.3.4 → 0.4.1

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.
@@ -214,10 +214,18 @@ class OINODbMsSql extends db_1.OINODb {
214
214
  return "'" + cellValue.toISOString().substring(0, 23) + "'";
215
215
  }
216
216
  else {
217
- // return "'" + cellValue?.toString().replaceAll("\\", "\\\\").replaceAll("\'", "''").replaceAll("\r", "\\r").replaceAll("\n", "\\n").replaceAll("\t", "\\t") + "'"
218
- return "'" + cellValue?.toString().replaceAll("\'", "''") + "'";
217
+ return this.printSqlString(cellValue.toString());
219
218
  }
220
219
  }
220
+ /**
221
+ * Print a single string value as valid sql literal
222
+ *
223
+ * @param sqlString string value
224
+ *
225
+ */
226
+ printSqlString(sqlString) {
227
+ return "'" + sqlString.replaceAll("'", "''") + "'";
228
+ }
221
229
  /**
222
230
  * Parse a single SQL result value for serialization using the context of the native data
223
231
  * type.
@@ -211,10 +211,18 @@ export class OINODbMsSql extends OINODb {
211
211
  return "'" + cellValue.toISOString().substring(0, 23) + "'";
212
212
  }
213
213
  else {
214
- // return "'" + cellValue?.toString().replaceAll("\\", "\\\\").replaceAll("\'", "''").replaceAll("\r", "\\r").replaceAll("\n", "\\n").replaceAll("\t", "\\t") + "'"
215
- return "'" + cellValue?.toString().replaceAll("\'", "''") + "'";
214
+ return this.printSqlString(cellValue.toString());
216
215
  }
217
216
  }
217
+ /**
218
+ * Print a single string value as valid sql literal
219
+ *
220
+ * @param sqlString string value
221
+ *
222
+ */
223
+ printSqlString(sqlString) {
224
+ return "'" + sqlString.replaceAll("'", "''") + "'";
225
+ }
218
226
  /**
219
227
  * Parse a single SQL result value for serialization using the context of the native data
220
228
  * type.
@@ -35,6 +35,13 @@ export declare class OINODbMsSql extends OINODb {
35
35
  *
36
36
  */
37
37
  printCellAsSqlValue(cellValue: OINODataCell, sqlType: string): string;
38
+ /**
39
+ * Print a single string value as valid sql literal
40
+ *
41
+ * @param sqlString string value
42
+ *
43
+ */
44
+ printSqlString(sqlString: string): string;
38
45
  /**
39
46
  * Parse a single SQL result value for serialization using the context of the native data
40
47
  * type.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db-mssql",
3
- "version": "0.3.4",
3
+ "version": "0.4.1",
4
4
  "description": "OINO TS package for using Microsoft Sql databases.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",
@@ -22,7 +22,7 @@
22
22
  "module": "./dist/esm/index.js",
23
23
  "types": "./dist/types/index.d.ts",
24
24
  "dependencies": {
25
- "@oino-ts/db": "0.3.4",
25
+ "@oino-ts/db": "0.4.1",
26
26
  "mssql": "^11.0.1"
27
27
  },
28
28
  "devDependencies": {
@@ -226,11 +226,20 @@ export class OINODbMsSql extends OINODb {
226
226
  return "'" + cellValue.toISOString().substring(0, 23) + "'"
227
227
 
228
228
  } else {
229
- // return "'" + cellValue?.toString().replaceAll("\\", "\\\\").replaceAll("\'", "''").replaceAll("\r", "\\r").replaceAll("\n", "\\n").replaceAll("\t", "\\t") + "'"
230
- return "'" + cellValue?.toString().replaceAll("\'", "''") + "'"
229
+ return this.printSqlString(cellValue.toString())
231
230
  }
232
231
  }
233
232
 
233
+ /**
234
+ * Print a single string value as valid sql literal
235
+ *
236
+ * @param sqlString string value
237
+ *
238
+ */
239
+ printSqlString(sqlString:string): string {
240
+ return "'" + sqlString.replaceAll("'", "''") + "'"
241
+ }
242
+
234
243
  /**
235
244
  * Parse a single SQL result value for serialization using the context of the native data
236
245
  * type.