datensatz einfuege test

This commit is contained in:
age 2008-01-11 03:55:55 +00:00
parent 24cfa4d3a8
commit 82a1b9dc69

View file

@ -2,43 +2,77 @@
import sys import sys
import MySQLdb import MySQLdb
from time import *
from datetime import *
prepare_event: class DataBase:
def connect(self):
self.db = MySQLdb.connect(db="szene",\
host="localhost", \
user="szene", \
passwd="szene", \
use_unicode=1)
print "Verbunden"
def close (self):
self.db.close()
print "Verbindung getrennt"
def get_latest_uid_category(self, type):
c = self.db.cursor()
#c.execute("""SELECT uid FROM tx_skcalendar_category""")
sqlqueue="SELECT uid FROM tx_skcalendar_" + type
c.execute(sqlqueue)
j=1
for i in c:
if i[0] > j:
j = i[0]
print "latest uid for %s is: %i" % (type, j)
return j
def prepare_event(self):
'''hiermit wird eine neue Veranstaltung in passender Form '''hiermit wird eine neue Veranstaltung in passender Form
fuer die VCE Extension vorbereitet''' fuer die VCE Extension vorbereitet'''
#uid = zuletzt in der DB vergebene um eine erhöhen self.event_pid = "29"
#pid = haengt von der Elternkategorie ab self.event_title = "Test2"
#tstamp = mktime(datetime.now().timetuple()) self.event_description = "blablabla"
#startdate = self.event_startdate = str(int(mktime((datetime(2008,01,31,11,11,00)).timetuple())))
#stat_time = self.event_targetgroup = "5"
#wholeday = 0|1 self.event_category = "1"
#enddate = self.event_organizer = "1"
#end_time = self.event_location = "1"
#link = self.event_tstamp = str(int(mktime(datetime.now().timetuple())))
#description = self.event_crdate = str(int(mktime(datetime.now().timetuple())))
#category =
#organizer =
#location =
def insert_event(self):
insert_event:
'''den MySQL Befehl absetzen''' '''den MySQL Befehl absetzen'''
#INSERT INTO `tx_skcalendar_event` ( `uid` , `pid` , `tstamp` , `crdate` , `cruser_id` , `t3ver_oid` , `t3ver_id` , `t3ver_wsid` , `t3ver_label` , `t3ver_state` , `t3ver_stage` , `t3ver_count` , `t3ver_tstamp` , `t3_origuid` , `sys_language_uid` , `l18n_parent` , `l18n_diffsource` , `deleted` , `hidden` , `fe_group` , `title` , `startdate` , `start_time` , `wholeday` , `enddate` , `end_time` , `link` , `description` , `recurring` , `recurr_until` , `cost` , `targetgroup` , `category` , `organizer` , `location` , `exeptions` , `image` , `dam_image` ) VALUES (self.uid, self.pid, '0', '0', '0', '0', '0', '0', '', '0', '0', '0', '0', '0', '0', '0', '', '0', '0', '0', self.title, self.startdate, self.start_time, self.wholeday, self.enddate, self.end_time, self.link, self.description, '0', '0', '0.00', '0', self.category, self.organizer, self.location, '', '', '0'); #sqlqueue="INSERT INTO `tx_skcalendar_event` (`pid`) VALUES ('29');"
self.prepare_event()
c = self.db.cursor()
sqlqueue="INSERT INTO `tx_skcalendar_event` (`pid` , `title`, `description`, `targetgroup`, `category`, `organizer`, `location`, `tstamp` , `crdate` ) VALUES (" \
+ "'" + self.event_pid + "', "\
+ "'" + self.event_title + "', "\
+ "'" + self.event_description + "', "\
+ "'" + self.event_targetgroup + "', "\
+ "'" + self.event_category + "', "\
+ "'" + self.event_organizer + "', "\
+ "'" + self.event_location + "', "\
+ "'" + self.event_tstamp + "', "\
+ "'" + self.event_crdate \
+ "');"
print sqlqueue
c.execute(sqlqueue)
## oder wenn werte aus einer liste: users = (bla, fasel, foo, bar)
## c.executemany("""INSERT INTO users (userid, first_name, last_name, company) VALUES (%s, %s, %s, %s)""", users)
## oder c.executemany( """INSERT INTO breakfast (name, spam, eggs, sausage, price) VALUES (%s, %s, %s, %s, %s)""", [ ("Spam and Sausage Lover's Plate", 5, 1, 8, 7.95 ), ("Not So Much Spam Plate", 3, 2, 0, 3.95 ), ("Don't Wany ANY SPAM! Plate", 0, 4, 3, 5.95 ) ] )
if __name__ == '__main__': if __name__ == '__main__':
test = DataBase()
try: test.connect()
conn = MySQLdb.connect(db="meinedatenbank", test.get_latest_uid_category("organizer")
host="localhost", #test.prepare_event()
user="ich", test.insert_event()
passwd="geheim") test.close()
print "Verbunden"
except:
print "Verbindungsfehler"
sys.exit(1)
conn.close()
print "Verbindung getrennt"
sys.exit(0) sys.exit(0)
@ -50,5 +84,10 @@ from datetime import *
datetime.fromtimestamp(1199142000) datetime.fromtimestamp(1199142000)
# und zurueck # und zurueck
mktime((datetime(2008,01,31,21,8,00)).timetuple()) mktime((datetime(2008,01,31,21,8,00)).timetuple())
## Python & MySQL
# http://www.kitebird.com/articles/pydbapi.html
# http://dustman.net/andy/python/python-and-mysql
''' '''