datensatz einfuege test
This commit is contained in:
parent
24cfa4d3a8
commit
82a1b9dc69
1 changed files with 72 additions and 33 deletions
|
@ -2,44 +2,78 @@
|
|||
|
||||
import sys
|
||||
import MySQLdb
|
||||
from time import *
|
||||
from datetime import *
|
||||
|
||||
prepare_event:
|
||||
'''hiermit wird eine neue Veranstaltung in passender Form
|
||||
fuer die VCE Extension vorbereitet'''
|
||||
#uid = zuletzt in der DB vergebene um eine erhöhen
|
||||
#pid = haengt von der Elternkategorie ab
|
||||
#tstamp = mktime(datetime.now().timetuple())
|
||||
#startdate =
|
||||
#stat_time =
|
||||
#wholeday = 0|1
|
||||
#enddate =
|
||||
#end_time =
|
||||
#link =
|
||||
#description =
|
||||
#category =
|
||||
#organizer =
|
||||
#location =
|
||||
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"
|
||||
|
||||
insert_event:
|
||||
'''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');
|
||||
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
|
||||
fuer die VCE Extension vorbereitet'''
|
||||
self.event_pid = "29"
|
||||
self.event_title = "Test2"
|
||||
self.event_description = "blablabla"
|
||||
self.event_startdate = str(int(mktime((datetime(2008,01,31,11,11,00)).timetuple())))
|
||||
self.event_targetgroup = "5"
|
||||
self.event_category = "1"
|
||||
self.event_organizer = "1"
|
||||
self.event_location = "1"
|
||||
self.event_tstamp = str(int(mktime(datetime.now().timetuple())))
|
||||
self.event_crdate = str(int(mktime(datetime.now().timetuple())))
|
||||
|
||||
def insert_event(self):
|
||||
'''den MySQL Befehl absetzen'''
|
||||
#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__':
|
||||
|
||||
try:
|
||||
conn = MySQLdb.connect(db="meinedatenbank",
|
||||
host="localhost",
|
||||
user="ich",
|
||||
passwd="geheim")
|
||||
print "Verbunden"
|
||||
except:
|
||||
print "Verbindungsfehler"
|
||||
sys.exit(1)
|
||||
|
||||
conn.close()
|
||||
print "Verbindung getrennt"
|
||||
sys.exit(0)
|
||||
test = DataBase()
|
||||
test.connect()
|
||||
test.get_latest_uid_category("organizer")
|
||||
#test.prepare_event()
|
||||
test.insert_event()
|
||||
test.close()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
'''
|
||||
|
@ -50,5 +84,10 @@ from datetime import *
|
|||
datetime.fromtimestamp(1199142000)
|
||||
# und zurueck
|
||||
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
|
||||
|
||||
'''
|
||||
|
||||
|
|
Loading…
Reference in a new issue