From b25c5d97f3450e9d73fe4d2f98914d5ea2e356f8 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Tue, 26 Sep 2017 18:17:34 +0300 Subject: [PATCH] Fixed import/export bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Which was there due to table and columns were not quoted. Also removed regex matching for columns during import, since we now support “everything” - According to MySQL’s dox at least … --- template/helpers/export-items.hl | 4 ++-- template/helpers/upload-file.hl | 28 +++++++++------------------- template/launch.hl | 2 +- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/template/helpers/export-items.hl b/template/helpers/export-items.hl index 281642f..241b320 100644 --- a/template/helpers/export-items.hl +++ b/template/helpers/export-items.hl @@ -37,7 +37,7 @@ for-each:x:/@load-file/*/*/field * Adding column to SQL. */ set:x:/@_cols?value - src:{0},{1} + src:{0},`{1}` :x:/@_cols?value :x:/@_dp/#/*/name?value @@ -64,7 +64,7 @@ p5.mysql.connect:[camphora] /* * Runninq query. */ - p5.mysql.select:@"select {0} from {1}" + p5.mysql.select:@"select {0} from `{1}`" :x:/@_cols?value :x:/../*/app-name?value diff --git a/template/helpers/upload-file.hl b/template/helpers/upload-file.hl index e4fce02..7c434d9 100644 --- a/template/helpers/upload-file.hl +++ b/template/helpers/upload-file.hl @@ -37,36 +37,26 @@ load-file:{0}{1}{2} _cols _pars .cols +_no:int:0 for-each:x:/@load-file/*/*/[0,1]/*?name - /* - * Sanity checking column name, to avoid SQL injection attacks. - */ - match:x:/@_dp?value - src:regex:"/^[_a-z]{3,}$/i" - if:x:/@match/*?count - =:int:0 - or:x:/@match/0?name - =: - - /* - * Malformed column name in CSV file. - */ - throw:Malformed column name in CSV file. - /* * Adding column to SQL. */ set:x:/@_cols?value - src:{0},{1} + src:{0},`{1}` :x:/@_cols?value :x:/@_dp?value set:x:/@_pars?value src:{0},@{1} :x:/@_pars?value - :x:/@_dp?value + :x:/@_no?value add:x:/@.cols - src:x:/@_dp?value + src:@{0} + :x:/@_no?value + set:x:/@_no?value + +:x:/@_no?value + _:1 @@ -125,7 +115,7 @@ p5.mysql.connect:[camphora] /* * Doing actual insertion of items. */ - p5.mysql.insert:@"insert into {0} ({1}) values ({2})" + p5.mysql.insert:@"insert into `{0}` ({1}) values ({2})" :x:/../*/app-name?value :x:/@_cols?value :x:/@_pars?value diff --git a/template/launch.hl b/template/launch.hl index 06e9bab..18d7d25 100644 --- a/template/launch.hl +++ b/template/launch.hl @@ -687,7 +687,7 @@ window.onscroll = function() { * Deleting all records from database. */ p5.mysql.connect:[camphora] - p5.mysql.delete:@"delete from {0}" + p5.mysql.delete:@"delete from `{0}`" :x:/@_app-name?value /*