Skip to content

Commit

Permalink
Fixed Java call not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Lade committed Nov 3, 2014
1 parent 40f665c commit 90de6c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Expand Up @@ -5,6 +5,7 @@ MAINTAINER Oliver Lade <oliver@similitude.org>

ENV H2_HOME /opt/h2
ENV H2_DATA /opt/h2-data
ENV H2_VERSION 1.4.182

ADD /api /api

9 changes: 5 additions & 4 deletions api/handler.py
Expand Up @@ -7,9 +7,10 @@ def query(self, sql):
"""
Executes the SQL query against the database and returns the results.
"""
cmd = 'java -cp %s/bin/h2*.jar org.h2.tools.Shell -url jdbc:h2:%s ' \
'-sql "%s"' % (os.environ['H2_HOME'], os.environ['H2_DATA'], sql)
return subprocess.call(cmd)
env = os.environ
cmd = 'java -cp %s/bin/h2-%s.jar org.h2.tools.Shell -url jdbc:h2:%s' % (
env['H2_HOME'], env['H2_VERSION'], env['H2_DATA'])
return subprocess.check_output(cmd.split() + ['-sql', sql])

def city_language(self, city):
"""
Expand All @@ -21,4 +22,4 @@ def city_language(self, city):
ORDER BY percentage DESC LIMIT 1;''' % city
# No need to protect against SQL injection, since the DB is transient.
result = self.query(sql)
return '%s (%s)' % result.splitlines()[1].split('\s+|\s+')
return '%s (%s)' % result.splitlines()[1].split('\s+|\s+')

0 comments on commit 90de6c8

Please sign in to comment.