commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue forms/samples/track/sql/dbschema.gsd desig...


From: Jan Ischebeck
Subject: gnue forms/samples/track/sql/dbschema.gsd desig...
Date: Wed, 24 Jul 2002 18:44:53 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jan Ischebeck <address@hidden>  02/07/24 18:44:53

Modified files:
        forms/samples/track/sql: dbschema.gsd 
        designer/src/forms/wizards: CreateSchema.py 

Log message:
        create schema from form wizard update: primary keys now supported
        updated example

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/samples/track/sql/dbschema.gsd.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/wizards/CreateSchema.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: gnue/designer/src/forms/wizards/CreateSchema.py
diff -c gnue/designer/src/forms/wizards/CreateSchema.py:1.4 
gnue/designer/src/forms/wizards/CreateSchema.py:1.5
*** gnue/designer/src/forms/wizards/CreateSchema.py:1.4 Wed Jul 24 16:55:16 2002
--- gnue/designer/src/forms/wizards/CreateSchema.py     Wed Jul 24 18:44:53 2002
***************
*** 100,110 ****
    #
    def Finalize(self):
  
!     self.fieldlistoftable = {}
      self.schema = GSSchema()
      self.gstables = GSTables(self.schema)
!     
!     self.form.walk(self.createschema)
  
      dest = open(self.variables['file'],"w")
      
--- 100,114 ----
    #
    def Finalize(self):
  
!     self.tablelist = {}
      self.schema = GSSchema()
      self.gstables = GSTables(self.schema)
! 
!     # Create Tables out of <datasource> tags
!     self.form.walk(self.CreateTables)
! 
!     # Populate tables with fields, primary and foreign keys
!     self.form.walk(self.PopulateSchema)
  
      dest = open(self.variables['file'],"w")
      
***************
*** 118,127 ****
  
      return 1
  
!   def createschema(self,obj):
!     # TODO: * create primary and foreign keys out of
!     #         master/detail relationships
!     #       * care for multiple fields in fk_descriptions
      #       * add error messages in case of missing/wrong datasources
      #         for a fk_source, or a datasource field (in <block ...>)
      #       * add a way to check for a datasource name with right case before
--- 122,157 ----
  
      return 1
  
!   def CreateTables(self,obj):
!     if obj._type=='GFDataSource':
!       
!       if hasattr(obj,'table'):
! 
!         #
!         # add the table
!         #
!         
!         newtable = GSTable(self.gstables)
!         newtable.name=obj.table
!         fields=GSFields(newtable)
!         fields=GSConstraints(newtable)
!         fields=GSPrimaryKey(newtable)
!         self.tablelist[string.lower(obj.name)]=newtable
! 
!       else:
!         print "WARNING: You defined a datasource without an 'table' "+\
!               "attribute."
!         
! 
!     elif obj._type=='GFBlock':
!       # if no datasource is defined for this block, create a default one
!       # or step over it (should be defined by options)
!       pass
!       
! 
!     
!   def PopulateSchema(self,obj):
!     # TODO: * care for multiple fields in fk_descriptions
      #       * add error messages in case of missing/wrong datasources
      #         for a fk_source, or a datasource field (in <block ...>)
      #       * add a way to check for a datasource name with right case before
***************
*** 129,191 ****
      #       * add a function for guessing row types
      
      if obj._type=='GFEntry':
-       myblock=obj.findParentOfType('GFBlock')
        
        if hasattr(obj,'field') and hasattr(myblock,'datasource') and \
!              self.fieldlistoftable.has_key(string.lower(myblock.datasource)):
          
!         newfield = GSField(self.fieldlistoftable[ \
!           string.lower(myblock.datasource)])
!         newfield.name=obj.field
!         newfield.type='string'
!         # print "adding '%s' field to table '%s'" % 
(obj.field,myblock.datasource)
        if hasattr(obj,'fk_key') and hasattr(obj,'fk_source') and\
!              self.fieldlistoftable.has_key(string.lower(obj.fk_source)):
          
!         newfield = GSField(self.fieldlistoftable[string.lower(obj.fk_source)])
!         newfield.name=obj.fk_key
!         newfield.type='string'
!         # print "adding '%s' field to table '%s'" % (obj.fk_key,obj.fk_source)
! 
!       if hasattr(obj,'fk_description') and hasattr(obj,'fk_source') and\
!              self.fieldlistoftable.has_key(string.lower(obj.fk_source)):
!         
!         newfield = GSField(self.fieldlistoftable[string.lower(obj.fk_source)])
!         newfield.name=obj.fk_description
!         newfield.type='string'
!         # print "adding '%s' field to table '%s'" % 
(obj.fk_description,obj.fk_source)
  
      elif obj._type=='GFDataSource':
        
        if hasattr(obj,'table'):
          
!         newtable = GSTable(self.gstables)
!         newtable.name=obj.table
!         fields=GSFields(newtable)
!         self.fieldlistoftable[string.lower(obj.name)]=fields
!         #print "add table '%s'" % obj.table
!         # check for masterlink
          if hasattr(obj,'master') and hasattr(obj,'masterlink') and \
                 hasattr(obj,'detaillink'):
            
            # create a foreign key on this table
!           newconstraint=GSConstraint(GSConstraints(newtable))
            newconstraint.name="fk_%s_%s" % (obj.table,obj.detaillink)
            newconstraint.type="foreignkey"
            nfk_field=GSConstraintField(newconstraint)
            nfk_field.name=obj.detaillink
            nfk_ref=GSConstraintRef(newconstraint)
            nfk_ref.name=obj.masterlink
-           nfk_ref.table=obj.master  # ERROR: should be replaced by dtssource
  
!           # create a field for that key (TODO: check for already defined keys)
!           newfield = GSField(fields)
!           newfield.name=obj.detaillink
!           newfield.type='string'
  
!           # create a primary key on the master table (TODO)
      else:
        pass
        
  
  ############
--- 159,261 ----
      #       * add a function for guessing row types
      
      if obj._type=='GFEntry':
        
+       myblock=obj.findParentOfType('GFBlock')
+ 
+       #
+       #  add a simple field to the table
+       #
        if hasattr(obj,'field') and hasattr(myblock,'datasource') and \
!              self.tablelist.has_key(string.lower(myblock.datasource)):
!         
!         table=self.tablelist[string.lower(myblock.datasource)]
          
!         self.AddField(table, obj.field, 'string')
! 
!       #
!       #  add fields to the table referenced in dropdowns
!       #
        if hasattr(obj,'fk_key') and hasattr(obj,'fk_source') and\
!              self.tablelist.has_key(string.lower(obj.fk_source)):
          
!         table=self.tablelist[string.lower(obj.fk_source)]
  
+         # add 'fk_key' field
+         self.AddField(table, obj.fk_key, 'string')
+ 
+         if hasattr(obj,'fk_description'):
+           
+           # add 'fk_description' field
+           self.AddField(table, obj.fk_description, 'string')
+ 
+         
      elif obj._type=='GFDataSource':
        
        if hasattr(obj,'table'):
          
!         #
!         # check for master/detail relation ship
!         #
!         
          if hasattr(obj,'master') and hasattr(obj,'masterlink') and \
                 hasattr(obj,'detaillink'):
            
+           table=self.tablelist[string.lower(obj.name)]
+           
            # create a foreign key on this table
!           newconstraint=GSConstraint(table.findChildOfType('GSConstraints'))
            newconstraint.name="fk_%s_%s" % (obj.table,obj.detaillink)
            newconstraint.type="foreignkey"
+           
            nfk_field=GSConstraintField(newconstraint)
            nfk_field.name=obj.detaillink
            nfk_ref=GSConstraintRef(newconstraint)
            nfk_ref.name=obj.masterlink
  
!           # create a field for that key 
!           self.AddField(table, obj.detaillink, 'string')
  
!           if self.tablelist[string.lower(obj.master)]:
!             
!             mtable=self.tablelist[string.lower(obj.master)]
!             # set table name for foreign key
!             nfk_ref.table=mtable.name
!                       
!             oldpkey=mtable.findChildOfType("GSPKField")
!             if oldpkey==None:
!               pkeyf=GSPKField(mtable.findChildOfType('GSPrimaryKey'))
!               pkeyf.name=obj.masterlink
!               
!               # add field              
!               self.AddField(mtable, obj.masterlink, 'string')
!               
!             elif oldpkey.name!=obj.masterlink:
!               print "WARNING: different primary keys computed out of "+\
!                     "master detail relationship ('%s'!='%s')." % \
!                     (oldpkey.name!=obj.masterlink)
!           else:
!             print "WARNING: master datasource is not defined in this file."
!             
!                                    
      else:
        pass
+     
+   def AddField(self,table,fieldname,type):
+     
+     fields = table.findChildOfType('GSFields')
+     
+     # check if field already exists
+     for child in fields._children:
+       if child._type == 'GSField' and child.name==fieldname:
+         # field already exists returning
+         # (possibly updating fieldtype here)
+         return
+       
+     # create field
+     newfield = GSField(fields)
+     newfield.name=fieldname
+     newfield.type=type
+     
        
  
  ############
Index: gnue/forms/samples/track/sql/dbschema.gsd
diff -c gnue/forms/samples/track/sql/dbschema.gsd:1.1 
gnue/forms/samples/track/sql/dbschema.gsd:1.2
*** gnue/forms/samples/track/sql/dbschema.gsd:1.1       Tue Jul 23 20:10:42 2002
--- gnue/forms/samples/track/sql/dbschema.gsd   Wed Jul 24 18:44:53 2002
***************
*** 1,6 ****
  <?xml version="1.0"?>
! <!--  GNUe Designer (0.3.0)
!       Schema saved on: 2002-XX-XX XX:XX:XX  -->
  <schema>
    <tables>
      <table name="person">
--- 1,6 ----
  <?xml version="1.0"?>
! <!-- Schema definition created by GNUe Designer's 
!      "Create Schema from Form" plugin -->
  <schema>
    <tables>
      <table name="person">
***************
*** 12,20 ****
--- 12,25 ----
          <field name="url" type="string"/>
          <field name="assignment_status" type="string"/>
        </fields>
+       <constraints/>
+       <primarykey>
+         <pkfield name="id"/>
+       </primarykey>
      </table>
      <table name="address">
        <fields>
+         <field name="personid" type="string"/>
          <field name="address_type" type="string"/>
          <field name="addr1" type="string"/>
          <field name="addr2" type="string"/>
***************
*** 23,70 ****
--- 28,107 ----
          <field name="zip" type="string"/>
          <field name="country" type="string"/>
        </fields>
+       <constraints>
+         <constraint name="fk_address_personid" type="foreignkey">
+           <constraintfield name="personid"/>
+           <constraintref name="id" table="person"/>
+         </constraint>
+       </constraints>
+       <primarykey/>
      </table>
      <table name="phone">
        <fields>
+         <field name="personid" type="string"/>
          <field name="phone_type" type="string"/>
          <field name="areacode" type="string"/>
          <field name="prefix" type="string"/>
          <field name="suffix" type="string"/>
          <field name="extension" type="string"/>
        </fields>
+       <constraints>
+         <constraint name="fk_phone_personid" type="foreignkey">
+           <constraintfield name="personid"/>
+           <constraintref name="id" table="person"/>
+         </constraint>
+       </constraints>
+       <primarykey/>
      </table>
      <table name="email">
        <fields>
+         <field name="personid" type="string"/>
          <field name="email_type" type="string"/>
          <field name="email" type="string"/>
        </fields>
+       <constraints>
+         <constraint name="fk_email_personid" type="foreignkey">
+           <constraintfield name="personid"/>
+           <constraintref name="id" table="person"/>
+         </constraint>
+       </constraints>
+       <primarykey/>
      </table>
      <table name="address_type">
        <fields>
          <field name="id" type="string"/>
          <field name="description" type="string"/>
        </fields>
+       <constraints/>
+       <primarykey/>
      </table>
      <table name="phone_type">
        <fields>
          <field name="id" type="string"/>
          <field name="description" type="string"/>
        </fields>
+       <constraints/>
+       <primarykey/>
      </table>
      <table name="email_type">
        <fields>
          <field name="id" type="string"/>
          <field name="description" type="string"/>
        </fields>
+       <constraints/>
+       <primarykey/>
      </table>
      <table name="assignment_status">
        <fields>
          <field name="id" type="string"/>
          <field name="status" type="string"/>
        </fields>
+       <constraints/>
+       <primarykey/>
      </table>
      <table name="history">
        <fields>
+         <field name="person" type="string"/>
          <field name="subject" type="string"/>
          <field name="contact_date" type="string"/>
          <field name="notes" type="string"/>
***************
*** 72,78 ****
          <field name="location" type="string"/>
          <field name="duration" type="string"/>
        </fields>
      </table>
    </tables>
  </schema>
- 
--- 109,121 ----
          <field name="location" type="string"/>
          <field name="duration" type="string"/>
        </fields>
+       <constraints>
+         <constraint name="fk_history_person" type="foreignkey">
+           <constraintfield name="person"/>
+           <constraintref name="id" table="person"/>
+         </constraint>
+       </constraints>
+       <primarykey/>
      </table>
    </tables>
  </schema>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]