def load_from_database(cls, resepti_id, ruokaaine_id): cur = cls.conn.cursor() cur.execute("SELECT resepti_id, ruokaaine_id, jarjestys, maara, mittayksikko FROM resepti_ruokaaine WHERE resepti_id = %s AND ruokaaine_id = %s", (int(resepti_id), int(ruokaaine_id))) row = cur.fetchone() resepti = Resepti.load_from_database(row[0]) ruokaaine = Ruokaaine.load_from_database(row[1]) resepti_ruokaaine = ReseptiRuokaaine(resepti, ruokaaine, row[2], row[3], row[4]) return resepti_ruokaaine
#!/usr/bin/python import os import pwd import psycopg2 from DatabaseObject import DatabaseObject from Resepti import Resepti dbuser = pwd.getpwuid(os.getuid()).pw_name dbname = dbuser conn = psycopg2.connect("dbname=%s user=%s" % (dbname, dbuser)) DatabaseObject.setDatabaseConnection(conn) for id in Resepti.load_ids(): o = Resepti.load_from_database(id) print ": %d -- %s" % (o.resepti_id, o.nimi)
import time import os import pwd import psycopg2 from DatabaseObject import DatabaseObject from Kommentti import Kommentti from Resepti import Resepti dbuser = pwd.getpwuid(os.getuid()).pw_name dbname = dbuser conn = psycopg2.connect("dbname=%s user=%s" % (dbname, dbuser)) DatabaseObject.setDatabaseConnection(conn) for id in Resepti.load_ids(): o = Resepti.load_from_database(id) print ": %d -- %s" % (o.resepti_id, o.nimi) for id in Kommentti.load_ids(): o = Kommentti.load_from_database(id) print ": %d -- %s %s" % (o.kommentti_id, o.aika, o.teksti) # print "new" # r = Resepti2.new('testi_' + str(time.time()), 'valmista') # print "update" # r.valmistusohje = r.valmistusohje + "_update" # r.save() # print "delete"