main logo
Subject: [dabo-dev] dabo Commit 1972
Author: Echo
Posted: 2006/02/28 13:51:18
 
View Entire Thread
New Search


dabo Commit
Revision 1972
Date: 2006-02-28 10:51:19 -0800 (Tue, 28 Feb 2006)
Author: echo

Changed:
U trunk/dabo/__init__.py
U trunk/dabo/biz/__init__.py
U trunk/dabo/dException.py
U trunk/dabo/db/__init__.py
U trunk/dabo/db/dBackend.py
U trunk/dabo/db/dConnection.py
U trunk/dabo/db/dCursorMixin.py
U trunk/dabo/db/dTable.py
U trunk/dabo/db/dbMySQL.py
U trunk/dabo/db/dbSQLite.py

Log:
Table creation now works for MySQL also.

The class dAutoBizobj is a bizobj that has a dTable.

The function AutoCreateTables() will try to create all the tables that have been setup with dAutoBizobj objects. If it can't create the tables, a message pops up for the user and the db admin. The db admin can enter the username and password for access to create tables or the db admin can manualy execute the queries in the queries.sql.

Also, having autotables for more than database or even more than one host does not messup or crash, it is handled.

Diff:
Modified: trunk/dabo/__init__.py
===================================================================
--- trunk/dabo/__init__.py 2006-02-26 22:38:48 UTC (rev 1971)
+++ trunk/dabo/__init__.py 2006-02-28 18:51:19 UTC (rev 1972)
@@ -118,5 +118,3 @@

# dApp will change the following values upon its __init__:
dAppRef = None
-
-

Modified: trunk/dabo/biz/__init__.py
===================================================================
--- trunk/dabo/biz/__init__.py 2006-02-26 22:38:48 UTC (rev 1971)
+++ trunk/dabo/biz/__init__.py 2006-02-28 18:51:19 UTC (rev 1972)
@@ -19,4 +19,5 @@

"""
from dBizobj import dBizobj
-
+from dAutoBizobj import dAutoBizobj
+from dAutoBizobj import AutoCreateTables

Modified: trunk/dabo/dException.py
===================================================================
--- trunk/dabo/dException.py 2006-02-26 22:38:48 UTC (rev 1971)
+++ trunk/dabo/dException.py 2006-02-28 18:51:19 UTC (rev 1972)
@@ -28,3 +28,21 @@

class ConnectionLostException(dException):
pass
+
+class DataBaseException(dException):
+ pass
+
+class DBNoAccessException(DataBaseException):
+ pass
+
+class DBNoDBOnHostException(DataBaseException):
+ pass
+
+class DBQueryException(DataBaseException):
+ def __init__(self, err, sql):
+ self.sql = sql
+ self.err_desc = str(err)
+
+ def __str__(self):
+ return self.err_desc + '\nSQL: ' + self.sql
+

Modified: trunk/dabo/db/__init__.py
===================================================================
--- trunk/dabo/db/__init__.py 2006-02-26 22:38:48 UTC (rev 1971)
+++ trunk/dabo/db/__init__.py 2006-02-28 18:51:19 UTC (rev 1972)
@@ -30,4 +30,4 @@
from dCursorMixin import dCursorMixin
from dMemento import dMemento
from dConnectInfo import dConnectInfo
-from dTable import dTable
+from dTable import dTable
\ No newline at end of file

Modified: trunk/dabo/db/dBackend.py
===================================================================
--- trunk/dabo/db/dBackend.py 2006-02-26 22:38:48 UTC (rev 1971)
+++ trunk/dabo/db/dBackend.py 2006-02-28 18:51:19 UTC (rev 1972)
@@ -3,6 +3,7 @@
from dabo.dLocalize import _
import dabo.dException as dException
from dabo.dObject import dObject
+from dabo.db import dTable


class dBackend(dObject):
@@ -388,6 +389,20 @@


########## Created by Echo ##############
+ def isExistingTable(self, table):
+ """Returns weather or not the table exists.
+ """
+ if isinstance(table, dTable):
+ return self._isExistingTable(table.name)
+ else:
+ return self._isExistingTable(table)
+
+
+ def _isExistingTable(self, tablename):
+ # OVERRIDE IN SUBCLASSES!
+ return False
+
+
def createJustTable(self, tabledef, cursor):
self.createTableAndIndex(tabledef, cursor, createIndexes=False)


Modified: trunk/dabo/db/dConnection.py
===================================================================
--- trunk/dabo/db/dConnection.py 2006-02-26 22:38:48 UTC (rev 1971)
+++ trunk/dabo/db/dConnection.py 2006-02-28 18:51:19 UTC (rev 1972)
@@ -1,3 +1,4 @@
+from dabo.dLocalize import _
from dabo.dObject import dObject
from dConnectInfo import dConnectInfo
from dCursorMixin import dCursorMixin
@@ -61,7 +62,11 @@
database object.
"""
return self._connectInfo.getBackendObject()
+
+ def _getConnInfo(self):
+ return self._connectInfo

+ ConnectInfo = property(_getConnInfo, None, None, _("The connectInfo for the connection. (class)"))

if __name__ == "__main__":
from dConnectInfo import dConnectInfo

Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2006-02-26 22:38:48 UTC (rev 1971)
+++ trunk/dabo/db/dCursorMixin.py 2006-02-28 18:51:19 UTC (rev 1972)
@@ -146,6 +146,7 @@
cursorToUse = self
else:
cursorToUse = self.AuxCursor
+ cursorToUse.AutoCommit = self.AutoCommit

# Some backends, notably Firebird, require that fields be specially
# marked.
@@ -169,7 +170,7 @@
if "connect" in str(e).lower():
raise dException.ConnectionLostException, e
else:
- raise dException.dException, e
+ raise dException.DBQueryException(e, sql)

if cursorToUse is not self:
# No need to manipulate the data

Modified: trunk/dabo/db/dTable.py
===================================================================
--- trunk/dabo/db/dTable.py 2006-02-26 22:38:48 UTC (rev 1971)
+++ trunk/dabo/db/dTable.py 2006-02-28 18:51:19 UTC (rev 1972)
@@ -16,8 +16,9 @@
field 3: 'last_name', it is a string field that has a max of 25
characters, NULL's are not allowed, part of an indexes
'idx_last' and 'idx_name'
- field 4: 'amount_owes', it is a float that has a precision of 2
- and uses 8 bytes, the default is 0
+ field 4: 'amount_owes', it is a float that has a total of 8 decimal places,
+ 2 of the decimal places are to the right of the point, uses 8 bytes,
+ and the default is 0

Code Example:
from dabo.db import dTable
@@ -29,7 +30,7 @@
myTable.addField(Name="last_name", DataType="string", Size=25,
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"))
"""
@@ -77,7 +78,10 @@
pass
else:
if pk == True:
- self._pk = name
+ if self._pk is None:
+ self._pk = [name]
+ else:
+ self._pk.append(name)

self._fields.append(dField(*args, **kwargs))

@@ -201,10 +205,10 @@
else:
pk = ""

- tmplt = "%s%s (%s, Size:%i, Precision:%i)%s %s Default:%s"
+ tmplt = "%s%s (%s, Size:%i, Total DP:%i Right DP:%i)%s %s Default:%s"
return tmplt % (self._name, pk, self._type.DataType,
- self._type.Size, self._type.Precision, autoi,
- allowednulls, self._default)
+ self._type.Size, self._type.TotalDP, self._type.RightDP,
+ autoi, allowednulls, self._default)


def _setAllowNulls(self, allow):
@@ -225,6 +229,12 @@
self._default = default

def _getDefault(self):
+ if self._default == None and self.IsPK:
+ if self.DataType == "Numeric":
+ self._default = '0'
+ else:
+ self._default = ''
+
return self._default


@@ -247,18 +257,25 @@

def _getName(self):
return self._name
+
+
+ def _setTotalDP(self, places):
+ self._type.TotalDP = places

-
- def _setPrecision(self, value):
- self._type.Precision = value
-
- def _getPrecision(self):
- return self._type.Precision
-
-
+ def _getTotalDP(self):
+ return self._type.TotalDP
+
+
+ def _setRightDP(self, places):
+ self._type.RightDP = places
+
+ def _getRightDP(self):
+ return self._type.RightDP
+
+
def _setSize(self, size):
self._type.Size = size
-
+
def _getSize(self):
return self._type.Size

@@ -290,12 +307,15 @@
Name = property(_getName, _setName, None,
_("The name of the table. (str)"))

- Precision = property(_getPrecision, _setPrecision, None,
- _("""The number of decimal places to the right of
- the period. (int)"""))
+ TotalDP = property(_getTotalDP, _setTotalDP, None,
+ _("The total number of decimal places (int)"
[excessive length snipped]
 
©2006 Echo
<-- Prior Message New Search Next Message -->