From 0caf73a9291d0e71eec5573b34a9c56914049fab Mon Sep 17 00:00:00 2001 From: antifaz Date: Tue, 10 Sep 2013 21:18:45 +0200 Subject: [PATCH] Inserita query --- server/techrec.db | Bin 4096 -> 2048 bytes server/techrec.py | 135 +++++++++++++++++++++++++++------------------- 2 files changed, 80 insertions(+), 55 deletions(-) diff --git a/server/techrec.db b/server/techrec.db index 35f48fe39db2ccfaaf8ac63d248fc14650bd93bc..9932f2dc6df9c7a6dfe72b42125f8c741e92f8e0 100644 GIT binary patch literal 2048 zcmWFz^vNtqRY=P(%1ta$FlJz3U}R))P*7lCVBi2^CLo3ZMj(R)#sShGJ|V!tp!-OZ z7pRJnIf(&?M!{$ZjIa=BlxAcX7Zzr0k}XM0%1JFsO$H(+=O9k1MpE=epZ!6pjK+fXw>$^wEseI0`$6}(*|6*MwaG`YZelbz`t1M@!SY0P=dZp?B_ z-+X?XA=fDV5=SbMUxI+Q}5FK*^ literal 4096 zcmeHIzi-n(82!$dx=A2VFii-hCOGv~mIJetob3VN9j+y_tm zuK$o%Y0I&#hD{pQ^_opMKvvSJmPfYh4f}@ekor!8)SI>1DoLk0ZrdmKEobYd<%E5| z;{~lzXg_ef!4#06?ZJ$p@Q$;6+j4fvEqj-&w7g=vILCJb;XmP?B>K(FZBHC(x^-D3pfm$Pi_w!Kg8bs2MT( zNg=v^LWbr3VtT6|`F>@M8RirueGEZK8f|~au@pQFl%|1b3K*XMr1T8%7yK4K#hW-IeUsjCATF^3|Iq>U z5>K7|BQ?la8ydeLOlF$HWEchLvJ8cT8)BH`28;@qRD0(z3ebz" % (self.id, self.name, self.starttime, self.endtime, self.state) + def __init__(self, name="", starttime=None, endtime=None, asjson=""): + self.error = 0 + self.values = {"name":"","starttime":"", "endtime":""} + if len(asjson) == 0: + self.name = name + self.starttime = starttime + self.endtime = endtime + else: + #try: + # dec = json.loads( unicode(asjson) ) + # dec = yaml.load( asjson ) + dec = json.dumps( asjson ) + # except: + # self.error = 0 + print("dec %s %s" % (dec,type(dec))) + print("asjson %s %s" % (asjson,type(asjson))) + + self.name = asjson[0]['name'] + self.starttime = asjson[0]['starttime'] + selfendtime = asjson[0]['endtime'] + + self.state = QUEUE + logging.info("New REC: ", self.values) + + # launch the job for processing files + def start(self): + # calcola file da splittare + pass + + def getvalue(self,val=None): + if val != None: + if self.values.has_key(val): + return self.values[val] + return self.values + + def err(self): + return self.error + + def set_run(self): + self.state = RUN + + def set_done(self): + self.state = DONE + + def __repr__(self): + return "" % (self.id, self.name, self.starttime, self.endtime, self.state) """ ************ RecDB @@ -101,20 +108,38 @@ class RecDB: # print all records def printall(self): - print("DB") + print(" ---- DB ---- ") allrecords = self.session.query(Rec).all() - for record in allrecords: - print("R: %s" % record) + print [ "R: %s" % record for record in allrecords ] + def execsql(self,sql): records = self.conn.execute( sql ) def search(self, name="", starttime="", endtime=""): - logging.debug("Looking for %s" % recfilter) + logging.debug("Looking for %s - %s - %s" % (name, starttime, endtime) ) - # self.session.query( Rec ).filter( Rec.name=name ).first() + ret = self.session.query(Rec).filter_by(name='Mimmo1').all() + print "[SEARCH] RET (",type(ret),")" , ret + for row in ret: + print "[SEARCH] Found:", row + +if __name__ == "__main__": + # text + db = RecDB() + + _mytime = datetime.datetime(2014,05,24,15,16,17) + a = Rec(name="Mimmo1", starttime=_mytime, endtime=None) - for row in records: - print "Found:", row + db.add( a ) + + raw_input() + + db.printall() + + raw_input() + # db.search( Rec(name="Mimmo1") ) + db.search( name="Mimmo1" ) + \ No newline at end of file