3 # Copyright 2011 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """An AJAX SQL shell sample app for Google Cloud SQL.
19 Deployed at http://sql-shell.appspot.com/
24 from google
.appengine
.api
import rdbms
25 from google
.appengine
.ext
import webapp
26 from google
.appengine
.ext
.webapp
import util
29 # rdbms db-api connection, globally cached
32 DATABASE_NAME
= 'shell'
33 INSTANCE
='google.com:speckle-python-demos:sqlshell-55'
36 class StatementHandler(webapp
.RequestHandler
):
37 """Runs a SQL statement and returns the result."""
40 self
.response
.headers
['Content-Type'] = 'text/plain'
42 statement
= self
.request
.get('statement')
47 cursor
= conn
.cursor()
48 logging
.info('Executing %r' % statement
)
49 cursor
.execute(statement
)
50 for results
in cursor
.fetchall():
51 self
.response
.out
.write('%s\r\n' % str(results
))
53 except rdbms
.Error
, e
:
54 logging
.exception('Error:')
55 self
.response
.out
.write(str(e
))
60 conn
= rdbms
.connect(instance
=INSTANCE
, database
=DATABASE_NAME
)
61 application
= webapp
.WSGIApplication([('/shell.do', StatementHandler
)],
63 util
.run_wsgi_app(application
)
66 if __name__
== '__main__':