diff options
author | Harel Ben-Attia <harelba@gmail.com> | 2014-06-14 08:26:06 -0400 |
---|---|---|
committer | Harel Ben-Attia <harelba@gmail.com> | 2014-06-14 08:26:06 -0400 |
commit | 705a6d17667492d9d79430ca1b69cc50c750579c (patch) | |
tree | fc055cc06bad7ea927479d679784d8de3eaf9e1a | |
parent | 6225144e7670e7e502ff2eb0d2dd0170db780127 (diff) |
Added fix for regexp handling of null and non string data
-rwxr-xr-x | bin/q | 7 | ||||
-rwxr-xr-x | test/test-suite | 30 |
2 files changed, 36 insertions, 1 deletions
@@ -165,7 +165,12 @@ parser.add_option_group(query_option_group) #----------------------------------------------- def regexp(regular_expression, data): - return re.search(regular_expression, data) is not None + if data is not None: + if type(data) is not str: + data = str(data) + return re.search(regular_expression, data) is not None + else: + return False class Sqlite3DBResults(object): def __init__(self,query_column_names,results): diff --git a/test/test-suite b/test/test-suite index bdf8dfb..3eaae0d 100755 --- a/test/test-suite +++ b/test/test-suite @@ -149,6 +149,36 @@ class BasicTests(AbstractQTestCase): self.assertTrue(e[1].startswith("Bad header row")) self.assertTrue("Column name cannot contain commas" in e[2]) + self.cleanup(tmpfile) + + def test_regexp_int_data_handling(self): + tmpfile = self.create_file_with_data(sample_data_no_header) + + cmd = '../bin/q -d , "select c2 from %s where regexp(\'^1\',c2)"' % tmpfile.name + retcode, o, e = run_command(cmd) + + self.assertEquals(retcode, 0) + self.assertEquals(len(o), 1) + self.assertEquals(len(e), 0) + + self.assertEquals(o[0],"1") + + self.cleanup(tmpfile) + + def test_regexp_null_data_handling(self): + tmpfile = self.create_file_with_data(sample_data_no_header) + + cmd = '../bin/q -d , "select count(*) from %s where regexp(\'^\',c2)"' % tmpfile.name + retcode, o, e = run_command(cmd) + + self.assertEquals(retcode, 0) + self.assertEquals(len(o), 1) + self.assertEquals(len(e), 0) + + self.assertEquals(o[0],"2") + + self.cleanup(tmpfile) + def test_select_one_column(self): tmpfile = self.create_file_with_data(sample_data_no_header) |