Google应用引擎数据存储区查询

时间:2011-11-17 19:05:50

标签: python google-app-engine

我已经为谷歌应用程序编写了这段代码,用于存储和检索数据输入并在浏览器窗口中显示它们。代码正在编译但是我如何检查它是否存储任何值以及进一步的SQL语法我写的是否正确?

import cgi
import datetime
import urllib
import wsgiref.handlers
import webapp2

from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class store(db.Model):
    cell = db.StringProperty()
    message = db.StringProperty()
    time = db.StringProperty()
    dateauto=db.DateTimeProperty(auto_now_add=True)

class Getdata(webapp2.RequestHandler):

    def prog (self,strg):
        message_split=strg.split('\n')
        message_split_second=strg.split(',')
        m_list=message_split[1:]
        collect_strings=''
        for j in m_list:
            collect_strings=collect_strings+j

        message_txt=collect_strings

        message_date=message_split_second[4]
        message_date=message_date.replace('"',"")
        dates=message_date

        message_time=message_split_second[5]
        message_time=message_time.split('/n')
        message_time=message_time[0]
        message_time=message_time.replace('"',"")
        temp=message_time.split('+')
        message_time=temp[0]
        times=message_time

        cell_number=message_split_second[2]
        cell_number=cell_number.replace('"',"")
        cellnum=cell_number
        return message_txt,dates,times,cellnum

    def post(self):
        self.response.headers['Content-Type'] = 'text/plain'
        strg=self.request.get('a')
        message_txt,dates,times,cellnum = self.prog(strg)
        log=store(cell=cellnum,message=message_txt,time=times)
        log.put()
        self.response.out.write(" ")

class MainPage(webapp2.RequestHandler):
    def get(self):
        dataout=db.GqlQuery("SELECT * FROM store",
                            "ORDER BY dateauto")  
    for message in dataout:
        self.response.out.write(dataout)

app = webapp2.WSGIApplication([('/', MainPage),
                           ('/sign', Getdata)],debug=True)
def main():
    run_wsgi_app(app)

if __name__ == '__main__':
    main()

'

1 个答案:

答案 0 :(得分:0)

从管理端口而不是普通端口访问服务器(对于我当前的项目,我将在浏览器中使用localhost:8004而不是localhost:13080)。单击“数据存储查看器”选项卡,查看存储的内容。

P.S。在数据存储区中,使用GQL而不是SQL。这类似于SQL,除了所有查询都以SELECT *开头,并且没有连接。