summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/q7
-rwxr-xr-xtest/test-suite30
2 files changed, 36 insertions, 1 deletions
diff --git a/bin/q b/bin/q
index e06a614..ab83146 100755
--- a/bin/q
+++ b/bin/q
@@ -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)