405 |
for f in (rs): |
for f in (rs): |
406 |
dict[string.lower(self._fieldNames[i])] = f |
dict[string.lower(self._fieldNames[i])] = f |
407 |
i += 1 |
i += 1 |
|
|
|
408 |
self._cachedRecords.append (self._recordSetClass(parent=self, \ |
self._cachedRecords.append (self._recordSetClass(parent=self, \ |
409 |
initialData=dict)) |
initialData=dict)) |
410 |
else: |
else: |
411 |
return 0 |
return 0 |
412 |
return 1 |
return 1 |
413 |
else: |
else: |
414 |
|
# We no longer need the cursor if we are read only |
415 |
|
if self._readonly: |
416 |
|
self._cursor.close() |
417 |
return 0 |
return 0 |
418 |
else: |
else: |
419 |
return 0 |
return 0 |
447 |
# These are probably not necessary now that null and not null exist |
# These are probably not necessary now that null and not null exist |
448 |
'__iseq': (2, 2, '(%s IS %s)', None ), |
'__iseq': (2, 2, '(%s IS %s)', None ), |
449 |
'__isne': (2, 2, '(%s IS NOT %s)', None )} |
'__isne': (2, 2, '(%s IS NOT %s)', None )} |
450 |
|
schema2nativeTypes={} |
451 |
|
|
452 |
def __init__(self, strictQueryCount=1): |
def __init__(self, strictQueryCount=1): |
453 |
GDataObjects.DataObject.__init__(self) |
GDataObjects.DataObject.__init__(self) |
494 |
if value == None: |
if value == None: |
495 |
return "NULL" |
return "NULL" |
496 |
elif type(value) == types.FloatType: |
elif type(value) == types.FloatType: |
497 |
return str(value) |
if value==int(value): |
498 |
|
return "%d" % value |
499 |
|
else: |
500 |
|
return str(value) |
501 |
else: |
else: |
502 |
return "'%s'" % string.replace(str(value),"'", |
return "'%s'" % string.replace(str(value),"'", |
503 |
"%s'" % self._escapeSingleQuote) |
"%s'" % self._escapeSingleQuote) |
682 |
def _beginTransaction(self): |
def _beginTransaction(self): |
683 |
pass |
pass |
684 |
|
|
685 |
|
|
686 |
|
def _buildFieldDefinition(self,field): |
687 |
|
try: |
688 |
|
sql="%s %s" % (field.name, |
689 |
|
self.schema2nativeTypes[field.type]) |
690 |
|
except: |
691 |
|
raise GDataObjects.DataTypeNotAvailable, \ |
692 |
|
"Datatype '%s' is not supported by database" |
693 |
|
|
694 |
|
if hasattr(field,"size"): |
695 |
|
sql=sql+"(%s)" % field.size |
696 |
|
|
697 |
|
# if hasattr(field,"precision"): |
698 |
|
# if hasattr(field,"scale"): |
699 |
|
|
700 |
|
if not field.nullable: |
701 |
|
sql=sql+" NOT NULL" |
702 |
|
|
703 |
|
if hasattr(field,"default"): |
704 |
|
sql=sql+" DEFAULT %s" % self._toSqlString(field.default) |
705 |
|
|
706 |
|
return sql |
707 |
|
|
708 |
|
def _buildTableDefinition(self,tbl): |
709 |
|
|
710 |
|
sql="CREATE TABLE %s (" % tbl.name |
711 |
|
|
712 |
|
|
713 |
|
# add fields to table |
714 |
|
|
715 |
|
fields=tbl.findChildOfType("GSFields") |
716 |
|
|
717 |
|
delim="" |
718 |
|
|
719 |
|
for field in fields._children: |
720 |
|
|
721 |
|
sql=sql+delim+"%s" % self._buildFieldDefinition(field) |
722 |
|
delim="," |
723 |
|
|
724 |
|
# define primary key |
725 |
|
|
726 |
|
pk=tbl.findChildOfType("GSPrimaryKey") |
727 |
|
|
728 |
|
if (pk!=None) and len(pk._children): |
729 |
|
|
730 |
|
sql=sql+", primary key %s (" % pk.name |
731 |
|
|
732 |
|
delim="" |
733 |
|
|
734 |
|
for pkfield in pk._children: |
735 |
|
|
736 |
|
sql=sql+delim+pkfield.name |
737 |
|
|
738 |
|
delim="," |
739 |
|
|
740 |
|
sql=sql+") " |
741 |
|
|
742 |
|
|
743 |
|
# close definition |
744 |
|
|
745 |
|
sql=sql+");" |
746 |
|
|
747 |
|
GDebug.printMesg(1,"SQL Statement: %s" % sql) |
748 |
|
|
749 |
|
return sql |
750 |
|
|
751 |
|
def writeTable(self,tbl,overwrite): |
752 |
|
|
753 |
|
sql = self._buildTableDefinition(tbl) |
754 |
|
|
755 |
|
try: |
756 |
|
cursor = self._dataConnection.cursor() |
757 |
|
cursor.execute(sql) |
758 |
|
cursor.close() |
759 |
|
except: |
760 |
|
# test it is an error because of an existing table |
761 |
|
# directly raise an error, if it is an access rights problem |
762 |
|
if not overwrite: |
763 |
|
return "Could not write table %s to database." % tbl.name |
764 |
|
else: |
765 |
|
cursor = self._dataConnection.cursor() |
766 |
|
# drop table |
767 |
|
cursor.execute("drop table %s" % tbl.name) |
768 |
|
# create table |
769 |
|
cursor.execute(sql) |
770 |
|
cursor.close() |
771 |
|
|
772 |
|
|
773 |
|
# write Schema to Database |
774 |
|
def writeSchema(self,obj,overwrite=0): |
775 |
|
if obj._type=="GSTable": |
776 |
|
return self.writeTable(obj,overwrite) |
777 |
|
|
778 |
|
elif obj._type=="GSView": |
779 |
|
return self.writeView(obj,overwrite) |
780 |
|
|
781 |
|
else: |
782 |
|
# do the same for all children |
783 |
|
result=[] |
784 |
|
for child in obj._children: |
785 |
|
result.append(self.writeSchema(child)) |
786 |
|
|
787 |
|
if len(result)==0: |
788 |
|
return None |
789 |
|
elif len(result)==1: |
790 |
|
return result[0] |
791 |
|
else: |
792 |
|
return result |
793 |
|
|
794 |
|
|
795 |
|
|
796 |
class DBSIG_DataObject_Object: |
class DBSIG_DataObject_Object: |
797 |
def __init__(self): |
def __init__(self): |
798 |
# TODO: A dummy placeholder to let old db driver work |
# TODO: A dummy placeholder to let old db driver work |
799 |
# TODO: each can have their *_DataObject_Object object from __init__ing |
# TODO: each can have their *_DataObject_Object object from __init__ing |
800 |
# TODO: DBSIG_DataObject_Object |
# TODO: DBSIG_DataObject_Object |
801 |
GDebug.printMesg(0, "Database driver needs updated to not initialize DBSIG_DataObject_Object") |
GDebug.printMesg(0, |
802 |
|
"Database driver needs updated to not initialize DBSIG_DataObject_Object") |
803 |
|
|
804 |
def _buildQuery(self, conditions={}, qTable=None): |
def _buildQuery(self, conditions={}, qTable=None): |
805 |
if not qTable: |
if not qTable: |
819 |
q = "%s ORDER BY %s " % (q, self.order_by) |
q = "%s ORDER BY %s " % (q, self.order_by) |
820 |
|
|
821 |
GDebug.printMesg(5,q) |
GDebug.printMesg(5,q) |
822 |
|
|
823 |
return q |
return q |
824 |
|
|
825 |
def _buildQueryCount(self, conditions={}): |
def _buildQueryCount(self, conditions={}): |