Parcourir la source

properly handle IN queries

Sven Klemm il y a 7 ans
Parent
commit
64fa1ce8a0
1 fichiers modifiés avec 6 ajouts et 5 suppressions
  1. 6 5
      public/app/plugins/datasource/postgres/postgres_query.ts

+ 6 - 5
public/app/plugins/datasource/postgres/postgres_query.ts

@@ -1,6 +1,5 @@
 import _ from 'lodash';
 import _ from 'lodash';
 import queryPart from './query_part';
 import queryPart from './query_part';
-import kbn from 'app/core/utils/kbn';
 
 
 export default class PostgresQuery {
 export default class PostgresQuery {
   target: any;
   target: any;
@@ -26,14 +25,16 @@ export default class PostgresQuery {
     target.select = target.select || [[{ type: 'column', params: ['value'] }]];
     target.select = target.select || [[{ type: 'column', params: ['value'] }]];
 
 
     this.updateProjection();
     this.updateProjection();
+    // give interpolateQueryStr access to this
+    this.interpolateQueryStr = this.interpolateQueryStr.bind(this);
   }
   }
 
 
   quoteIdentifier(value) {
   quoteIdentifier(value) {
-    return '"' + value + '"';
+    return '"' + value.replace('"','""') + '"';
   }
   }
 
 
   quoteLiteral(value) {
   quoteLiteral(value) {
-    return "'" + value + "'";
+    return "'" + value.replace("'","''") + "'";
   }
   }
 
 
   updateProjection() {
   updateProjection() {
@@ -147,10 +148,10 @@ export default class PostgresQuery {
     }
     }
 
 
     if (typeof value === 'string') {
     if (typeof value === 'string') {
-      return kbn.regexEscape(value);
+      return this.quoteLiteral(value);
     }
     }
 
 
-    var escapedValues = _.map(value, kbn.regexEscape);
+    var escapedValues = _.map(value, this.quoteLiteral);
     return '(' + escapedValues.join(',') + ')';
     return '(' + escapedValues.join(',') + ')';
   }
   }