Update of /cvsroot/webware/Webware/MiddleKit/Design
In directory usw-pr-cvs1:/tmp/cvs-serv28635
Modified Files:
MSSQLPythonGenerator.py MSSQLSQLGenerator.py
Log Message:
synchronized with latest MK conventions
Index: MSSQLPythonGenerator.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/MSSQLPythonGenerator.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** MSSQLPythonGenerator.py 29 Mar 2002 05:16:28 -0000 1.2
--- MSSQLPythonGenerator.py 8 Aug 2002 19:47:00 -0000 1.3
***************
*** 5,23 ****
pass
- class ObjRefAttr:
-
- def writePySet(self, out):
- name = self.name()
- pySetName = self.pySetName()
- targetClassName = self.className()
- if self.isRequired():
- reqAssert = 'assert value is not None'
- else:
- reqAssert = ''
- out.write('''
- def %(pySetName)s(self, value):
- %(reqAssert)s
- if value is not None and type(value) is not LongType:
- assert type(value) is InstanceType
- ''' % locals())
- self.writePySetAssignment(out.write, name)
--- 5,6 ----
Index: MSSQLSQLGenerator.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Design/MSSQLSQLGenerator.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** MSSQLSQLGenerator.py 20 Jun 2002 17:47:45 -0000 1.7
--- MSSQLSQLGenerator.py 8 Aug 2002 19:47:00 -0000 1.8
***************
*** 9,18 ****
return 0 # I think it does but I do not know how it is implemented
- pass
-
! # @@ 2000-09-14 ce: Some of the methods here are generic enough for SQLGenerator,
! # but our class fusing code doesn't handle classes found in the modules of
! # ancestor classes of the generator class.
--- 9,14 ----
return 0 # I think it does but I do not know how it is implemented
! pass
***************
*** 30,34 ****
def dropDatabaseSQL(self, dbName):
! """
Rather than drop the database, I prefer to drop just the tables.
The reason is that the database in MSSQL can contain users and diagrams that would then need to be re-added or re-created
--- 26,30 ----
def dropDatabaseSQL(self, dbName):
! '''
Rather than drop the database, I prefer to drop just the tables.
The reason is that the database in MSSQL can contain users and diagrams that would then need to be re-added or re-created
***************
*** 36,62 ****
What is even worse is that identity resets behave differently depending on whether data has existed in them at any given point.
Its safer to drop the table. dr 4-11-2001
! """
strList = []
! strList.append('use %s\ngo\n' % dbName)
! self._klasses.reverse()
! for klass in self._model._allKlassesInOrder:
# If table exists drop.
strList.append("print 'Dropping table %s'\n" % klass.name())
strList.append("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[%s]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)\n" % klass.name() )
! strList.append('drop table [dbo].[%s]\n' % klass.name())
strList.append('go\n\n')
self._klasses.reverse()
!
! return ''.join(strList) # I do not want to drop by dbase since I lose my users I've added to it
! # return 'drop database %s;\n' % dbName
def createDatabaseSQL(self, dbName):
! """
Creates the database only if it does not already exist
! """
! return 'Use Master\n' + 'go\n\n' + "if not exists( select * from master.dbo.sysdatabases where name = N'%s' ) create database %s; \n" % (dbName, dbName)
def useDatabaseSQL(self, dbName):
! return 'use %s;\n\n' % dbName
def sqlGenerator(self):
--- 32,74 ----
What is even worse is that identity resets behave differently depending on whether data has existed in them at any given point.
Its safer to drop the table. dr 4-11-2001
! '''
strList = []
! # strList.append('use %s\ngo\n' % dbName)
! strList.append('use Master\ngo\n')
! strList.append("if exists( select * from master.dbo.sysdatabases where name = N'%s') drop database %s;\ngo \n" % (dbName, dbName))
!
! if 0:
! self._klasses.reverse()
! for klass in self._klasses:
! # If table exists drop.
! strList.append("print 'Dropping table %s'\n" % klass.name())
! strList.append("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[%s]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)\n" % klass.name() )
! strList.append('drop table [dbo].%s\n' % klass.sqlTableName())
! strList.append('go\n\n')
! self._klasses.reverse()
!
! return ''.join(strList)
!
! def dropTablesSQL(self):
! strList = []
! self._klasses.reverse()
! for klass in self._klasses:
# If table exists drop.
strList.append("print 'Dropping table %s'\n" % klass.name())
strList.append("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[%s]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)\n" % klass.name() )
! strList.append('drop table [dbo].%s\n' % klass.sqlTableName())
strList.append('go\n\n')
self._klasses.reverse()
! return ''.join(strList)
!
def createDatabaseSQL(self, dbName):
! '''
Creates the database only if it does not already exist
! '''
! return 'Use Master\n' + 'go\n\n' + "if not exists( select * from master.dbo.sysdatabases where name = N'%s' ) create database %s;\ngo \n" % (dbName, dbName)
def useDatabaseSQL(self, dbName):
! return 'USE %s;\n\n' % dbName
def sqlGenerator(self):
***************
*** 68,75 ****
def writeClassIdsSQL(self, generator, out):
wr = out.write
! # If _MKClassIds table exists drop it before creating it again.
wr('''\
! if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[_MKClassIds]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[_MKClassIds]
go
--- 80,87 ----
def writeClassIdsSQL(self, generator, out):
wr = out.write
! # If _MKClassIds table exists drop it before creating it again.
wr('''\
! if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[_MKClassIds]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[_MKClassIds]
go
***************
*** 82,88 ****
wr('delete from _MKClassIds\n\n')
id = 1
! for klass in self._model._allKlassesInOrder:
wr('insert into _MKClassIds (id, name) values\n')
! wr ('\t(%s, %r)\n' % (id, klass.name()))
klass.setId(id)
id += 1
--- 94,103 ----
wr('delete from _MKClassIds\n\n')
id = 1
! for klass in self._klasses:
wr('insert into _MKClassIds (id, name) values\n')
! name = klass.name()
! # name = name.replace('[','')
! # name = name.replace(']','')
! wr ('\t(%s, %r)\n' % (id, name))
klass.setId(id)
id += 1
***************
*** 91,95 ****
def writeKeyValue(self, out, key, value):
! """ Used by willWriteSQL(). """
key = ljust(key, 12)
out.write('# %s = %s\n' % (key, value))
--- 106,110 ----
def writeKeyValue(self, out, key, value):
! ''' Used by willWriteSQL(). '''
key = ljust(key, 12)
out.write('# %s = %s\n' % (key, value))
***************
*** 106,110 ****
kv(out, 'Num classes', len(self._klasses))
wr('\nClasses:\n')
! for klass in self._model._allKlasses:
wr('\t%s\n' % klass.name())
wr('*/\n\n')
--- 121,125 ----
kv(out, 'Num classes', len(self._klasses))
wr('\nClasses:\n')
! for klass in self._klasses:
wr('\t%s\n' % klass.name())
wr('*/\n\n')
***************
*** 116,123 ****
# If database doesn't exist create it.
dbName = generator.dbName()
! wr('Use %s\ngo\n\n' % dbName)\
!
! rList = self._model._allKlassesInOrder[:]
rList.reverse()
# print str(type(rList))
--- 131,138 ----
# If database doesn't exist create it.
dbName = generator.dbName()
! # wr('Use %s\ngo\n\n' % dbName)\
!
! rList = self._klasses[:]
rList.reverse()
# print str(type(rList))
***************
*** 146,157 ****
# wr(' %s bigint primary key not null IDENTITY (1, 1),\n' % ljust(sqlIdName, self.maxNameWidth()))
! # for attr in self.allDataAttrs():
# attr.writeSQL(generator, out)
!
# wr(' unique (%s)\n' % sqlIdName)
# wr(')\ngo\n\n\n')
def sqlIdName(self):
! name = self.name()
if name:
name = lower(name[0]) + name[1:] + 'Id'
--- 161,172 ----
# wr(' %s bigint primary key not null IDENTITY (1, 1),\n' % ljust(sqlIdName, self.maxNameWidth()))
! # for attr in self.allAttrs():
# attr.writeSQL(generator, out)
!
# wr(' unique (%s)\n' % sqlIdName)
# wr(')\ngo\n\n\n')
def sqlIdName(self):
! name = self._name # do not need or want protected name
if name:
name = lower(name[0]) + name[1:] + 'Id'
***************
*** 162,174 ****
def primaryKeySQLDef(self, generator):
! """
! Returns a one liner that becomes part of the CREATE
! statement for creating the primary key of the
! table. SQL generators often override this mix-in
! method to customize the creation of the primary key
! for their SQL variant. This method should use
! self.sqlIdName() and often ljust()s it by
! self.maxNameWidth().
! """
# print("print 'Creating table %s'\n" % name)
--- 177,183 ----
def primaryKeySQLDef(self, generator):
! '''
! Returns a one liner that becomes part of the CREATE statement for creating the primary key of the table. SQL generators often override this mix-in method to customize the creation of the primary key for their SQL variant. This method should use self.sqlIdName() and often ljust()s it by self.maxNameWidth().
! '''
# print("print 'Creating table %s'\n" % name)
***************
*** 179,188 ****
class Attr:
def _writeSQL(self, generator, out):
if self.hasSQLColumn():
name = ljust(self.sqlName(), self.maxNameWidth())
! out.write('\t%s %s null,\n' % (name, self.sqlType()))
else:
out.write('\t/* %(Name)s %(Type)s - not a SQL column */\n' % self)
--- 188,213 ----
+ # def name(self):
+ # return '[' + self._name + ']'
+
+
+ def sqlTableName(self):
+ """
+ Returns "[name]" so that table names do not conflict with SQL
+ reserved words.
+ """
+ return '[%s]' % self.name()
+
+
+
class Attr:
+ def sqlNullSpec(self):
+ return ' null'
+
def _writeSQL(self, generator, out):
if self.hasSQLColumn():
name = ljust(self.sqlName(), self.maxNameWidth())
! out.write('\t[%s] %s null,\n' % (name, self.sqlType()))
else:
out.write('\t/* %(Name)s %(Type)s - not a SQL column */\n' % self)
***************
*** 196,199 ****
--- 221,234 ----
raise SubclassResponsibilityError
+ def sqlName(self):
+ return '[' + self.name() + ']'
+
+ def sqlColumnName(self):
+ """ Returns the SQL column name corresponding to this attribute, consisting of self.name() + self.sqlTypeSuffix(). """
+ if not self._sqlColumnName:
+ self._sqlColumnName = self.name() # + self.sqlTypeSuffix()
+ return '[' + self._sqlColumnName + ']'
+
+
class DateTimeAttr:
def sqlType(self):
***************
*** 211,215 ****
def sqlType(self):
! # @@
return 'bit'
--- 246,250 ----
def sqlType(self):
! # @@
return 'bit'
***************
*** 228,232 ****
return 'decimal(%s,%s)' % (length,precision)
!
class LongAttr:
--- 263,267 ----
return 'decimal(%s,%s)' % (length,precision)
!
class LongAttr:
***************
*** 268,272 ****
else:
return 'bigint /* relates to %s */ ' % self['Type']
!
--- 303,307 ----
else:
return 'bigint /* relates to %s */ ' % self['Type']
!
***************
*** 288,289 ****
--- 323,326 ----
float(value) # raises exception if value is invalid
return value
+
+
|