main logo
Subject: [dabo-dev] dabodemo Commit 382
Author: Echo
Posted: 2006/02/28 13:52:02
 
View Entire Thread
New Search


dabodemo Commit
Revision 382
Date: 2006-02-28 10:52:03 -0800 (Tue, 28 Feb 2006)
Author: echo

Changed:
A trunk/db/autoCreateTable.py
U trunk/db/createTable.py

Log:
fixed up and added another demo for creating tables

Diff:
Added: trunk/db/autoCreateTable.py
===================================================================
--- trunk/db/autoCreateTable.py 2006-02-24 04:42:32 UTC (rev 381)
+++ trunk/db/autoCreateTable.py 2006-02-28 18:52:03 UTC (rev 382)
@@ -0,0 +1,37 @@
+import dabo
+dabo.ui.loadUI("wx")
+from dabo.db import dTable
+import dabo.biz.dAutoBizobj as autobiz
+
+def main():
+ #Connect to database
+ ci = dabo.db.dConnectInfo(DbType="SQLite", Database="act.db")
+ conn = dabo.db.dConnection(ci)
+
+ class table1(autobiz):
+ def afterInit(self):
+ t = dTable(Name="table1")
+ t.addField(Name="id", DataType="int", Size=8, IsPK=True)
+ self.Table = t
+ mytable1 = table1(conn)
+
+ class table2(autobiz):
+ def afterInit(self):
+ t = dTable(Name="table2")
+ t.addField(Name="id", DataType="int", Size=8, IsPK=True)
+ t.addField(Name="data", DataType="string", Size=25)
+ t.addIndex(Name="idx_data", Fields="data")
+ self.Table = t
+ mytable2 = table2(conn)
+
+ dabo.biz.AutoCreateTables()
+
+class f(dabo.ui.dForm):
+ def afterInit(self):
+ dabo.ui.callAfter(main)
+
+if __name__ == "__main__":
+ app = dabo.dApp()
+ app.MainFormClass = f
+ app.start()
+
\ No newline at end of file

Modified: trunk/db/createTable.py
===================================================================
--- trunk/db/createTable.py 2006-02-24 04:42:32 UTC (rev 381)
+++ trunk/db/createTable.py 2006-02-28 18:52:03 UTC (rev 382)
@@ -3,11 +3,11 @@
import dabo.biz as biz

def main():
- #connect to database
+ #Connect to database
ci = dabo.db.dConnectInfo(DbType="SQLite", Database="bla.db")
conn = dabo.db.dConnection(ci)

- # Get a dabo Cursor object from the connection:
+ #Get a dabo Cursor object from the connection:
cur = conn.getDaboCursor()

#Set up the table definition
@@ -15,11 +15,11 @@
mytable.addField(Name="theid", IsPK=True, DataType="int", Size=2,
IsAutoIncrement=True)
mytable.addField(Name="first_name", DataType="string", Size=25,
- Index="idx_first")
+ Default='', Index="idx_first")
mytable.addField(Name="last_name", DataType="string", Size=25,
- AllowNulls=False, Index="idx_last")
+ Default='', AllowNulls=False, Index="idx_last")
mytable.addField(Name="amount_owes", DataType="float",
- Precision=2, Size=8, Default=0)
+ TotalDP=8, RightDP=2, Size=8, Default=0)

# When you want to have more than one field in an index, use AddIndex().
mytable.addIndex(Name="idx_name", Fields=("last_name","first_name"))
@@ -29,43 +29,35 @@
# Optionaly, you can call cur.createTable(mytable), insert your data
# and then call cur.createIndexes(mytable)

-#- #Insert some test data
-#- class testbiz(biz.dBizobj):
-#- def initProperties(self):
-#- self.Caption = "mytesttable"
-#- self.DataSource = "mytesttable"
-#- self.KeyField = "theid"
-#- self.RequeryOnLoad = False
-#- self.Encoding = "latin-1"
-#-
-#- def afterInit(self):
-#- self.setBaseSQL()
-#-
-#- def setBaseSQL(self):
-#- self.addFrom("mytesttable")
-#- self.addField("mytesttable.theid as theid")
-#- self.addField("mytesttable.first_name as first_name")
-#- self.addField("mytesttable.last_name as last_name")
-#- self.addField("mytesttable.amount_owes as amount_owes")
-#-
-#- mybiz = testbiz(conn)
-#- mybiz.new()
-#- mybiz.first_name = "Brandon"
-#- mybiz.last_name = "Singer"
-#- mybiz.amount_owes = 1234.01
-#- mybiz.save()
+ #Insert some test data
+ class testbiz(biz.dBizobj):
+ def initProperties(self):
+ self.Caption = "mytesttable"
+ self.DataSource = "mytesttable"
+ self.KeyField = "theid"
+ self.RequeryOnLoad = False
+ self.Encoding = "latin-1"
+
+ def afterInit(self):
+ self.setBaseSQL()
+
+ def setBaseSQL(self):
+ self.addFrom("mytesttable")
+ self.addField("mytesttable.theid as theid")
+ self.addField("mytesttable.first_name as first_name")
+ self.addField("mytesttable.last_name as last_name")
+ self.addField("mytesttable.amount_owes as amount_owes")

- #cur.execute("INSERT INTO mytesttable (first_name,last_name,
- #amount_owes) VALUES ("Brandon", "Singer", 1234.01)")
- #cur.execute("INSERT INTO mytesttable (first_name,last_name,
- #amount_owes) VALUES ("Dabo", "", -123)")
- #cur.save()
+ mybiz = testbiz(conn)
+ mybiz.requery()

- #print cur.execute("select * from mytesttable")
- #for row in cur.fetchall():
- # print row[0], row[1], row[2], row[3]
+ mybiz.new()
+ mybiz.first_name = "Brandon"
+ mybiz.last_name = "Singer"
+ mybiz.amount_owes = 1234.01
+ mybiz.save()

+ print mybiz.getDataSet()

if __name__ == "__main__":
- print
main()





 
©2006 Echo
<-- Prior Message New Search Next Message -->