[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5106 - trunk/gnue-common/src/schema/scripter/processors
From: |
johannes |
Subject: |
r5106 - trunk/gnue-common/src/schema/scripter/processors |
Date: |
Fri, 13 Feb 2004 11:11:23 -0600 (CST) |
Author: johannes
Date: 2004-02-13 11:11:22 -0600 (Fri, 13 Feb 2004)
New Revision: 5106
Added:
trunk/gnue-common/src/schema/scripter/processors/mssql.py
Modified:
trunk/gnue-common/src/schema/scripter/processors/SQL.py
trunk/gnue-common/src/schema/scripter/processors/__init__.py
trunk/gnue-common/src/schema/scripter/processors/interbase.py
trunk/gnue-common/src/schema/scripter/processors/mysql.py
trunk/gnue-common/src/schema/scripter/processors/postgresql.py
Log:
Added a processor for MS SQL (datetime-stuff needs some additional efforts) and
did some minor improvements to the other processors.
Modified: trunk/gnue-common/src/schema/scripter/processors/SQL.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/SQL.py 2004-02-12
16:06:03 UTC (rev 5105)
+++ trunk/gnue-common/src/schema/scripter/processors/SQL.py 2004-02-13
17:11:22 UTC (rev 5106)
@@ -141,3 +141,8 @@
"""
return "timestamp"
+ # ---------------------------------------------------------------------------
+ # Keep text as 'text'
+ # ---------------------------------------------------------------------------
+ def text (self, gsField):
+ return "text"
Modified: trunk/gnue-common/src/schema/scripter/processors/__init__.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/__init__.py
2004-02-12 16:06:03 UTC (rev 5105)
+++ trunk/gnue-common/src/schema/scripter/processors/__init__.py
2004-02-13 17:11:22 UTC (rev 5106)
@@ -1 +1 @@
-vendors = ['postgresql','oracle','interbase','mysql']
+vendors = ['postgresql','oracle','interbase','mysql','mssql']
Modified: trunk/gnue-common/src/schema/scripter/processors/interbase.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/interbase.py
2004-02-12 16:06:03 UTC (rev 5105)
+++ trunk/gnue-common/src/schema/scripter/processors/interbase.py
2004-02-13 17:11:22 UTC (rev 5106)
@@ -18,7 +18,7 @@
#
# Copyright 2002-2004 Free Software Foundation
#
-# $Id: $
+# $Id$
#
from gnue.common.schema.scripter.processors.SQL import SQLProcessor
@@ -66,14 +66,15 @@
# Add a generator trigger to the table definition
# ---------------------------------------------------------------------------
def __addTrigger (self, tableDef, gsField, gen):
- # TODO: check if this trigger code really makes sense !
epi = tableDef.epilogue
+ epi.append ("")
epi.append ("SET TERM ^ ;")
- epi.append ("CREATE TRIGGER trg_%s FOR %s ACTIVE BEFORE INSERT %s" % \
- (gsField.name, gen, "POSITION 0 AS BEGIN"))
- epi.append (" new.%s=gen_id(%s,1);" % (gsField.name, gen))
- epi.append ("END ^")
- epi.append ("SET TERM ;^")
+ epi.append ("CREATE TRIGGER trg_%s FOR %s" % (gsField.name, gen))
+ epi.append (" ACTIVE BEFORE INSERT POSITION 0 AS")
+ epi.append (" BEGIN")
+ epi.append (" NEW.%s = GEN_ID (%s,1);" % (gsField.name, gen))
+ epi.append (" END ^")
+ epi.append ("SET TERM ; ^")
# ===========================================================================
@@ -87,18 +88,6 @@
return "integer"
# ---------------------------------------------------------------------------
- # Time becomes 'date'
- # ---------------------------------------------------------------------------
- def time (self, gsField):
- return "date"
-
- # ---------------------------------------------------------------------------
- # Timestampe becomes 'date'
- # ---------------------------------------------------------------------------
- def timestamp (self, gsField):
- return "date"
-
- # ---------------------------------------------------------------------------
# Text becomes either 'string' or 'blob'
# ---------------------------------------------------------------------------
def text (self, gsField):
@@ -119,11 +108,11 @@
return "integer"
else:
- return "decimal(%s,0)" % gsField.length
+ return "numeric (%s,0)" % gsField.length
else:
- return "numeric(%s,%s)" % (gsField.length + gsField.precision,
- gsField.precision)
+ return "numeric (%s,%s)" % (gsField.length + gsField.precision,
+ gsField.precision)
# ---------------------------------------------------------------------------
# boolean becomes a number; TODO: add some check-constraints
Added: trunk/gnue-common/src/schema/scripter/processors/mssql.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/mssql.py 2004-02-12
16:06:03 UTC (rev 5105)
+++ trunk/gnue-common/src/schema/scripter/processors/mssql.py 2004-02-13
17:11:22 UTC (rev 5106)
@@ -0,0 +1,138 @@
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2002-2004 Free Software Foundation
+#
+# $Id$
+#
+
+from gnue.common.schema.scripter.processors.SQL import SQLProcessor
+from string import join
+
+name = "MSSQL"
+description = "MS SQL Server"
+
+# =============================================================================
+# GSD processor for MS SQL Server
+# =============================================================================
+class Processor (SQLProcessor):
+
+ MAX_NAME_LENGTH = 31
+
+ # ---------------------------------------------------------------------------
+ # Process a GSField instance
+ # ---------------------------------------------------------------------------
+ def addField (self, tableDef, gsField):
+ field = self._qualify (gsField)
+
+ # build a default value for this field
+ if gsField.defaultwith == "serial":
+ field += " IDENTITY"
+
+ elif gsField.defaultwith == "timestamp":
+ field += " DEFAULT GETDATE ()"
+
+ elif hasattr (gsField, "default") and len (gsField.default):
+ field += " DEFAULT %s" % gsField.default
+
+ if not gsField.nullable:
+ field += " NOT NULL"
+
+ tableDef.fields.append (field)
+
+ # ===========================================================================
+ # Datatype translation
+ # ===========================================================================
+
+ # ---------------------------------------------------------------------------
+ # A key field is of type 'int'
+ # ---------------------------------------------------------------------------
+ def key (self, gsField):
+ return "int"
+
+ # ---------------------------------------------------------------------------
+ # A number needs special treatment
+ # ---------------------------------------------------------------------------
+ def number (self, gsField):
+ if gsField.precision == 0:
+ if gsField.length <= 4:
+ return "smallint"
+
+ elif gsField.length <= 9:
+ return "int"
+
+ elif gsField.length <= 18:
+ return "bigint"
+
+ else:
+ return "decimal (%s,0)" % gsField.length
+ else:
+ return "decimal (%s,%s)" % (gsField.length + gsField.precision,
+ gsField.precision)
+
+ # ---------------------------------------------------------------------------
+ # Keep boolean as 'boolean'
+ # ---------------------------------------------------------------------------
+ def boolean (self, gsField):
+ return "bit"
+
+ # ---------------------------------------------------------------------------
+ # datetime is not equivalent to timestamp
+ # ---------------------------------------------------------------------------
+ def datetime (self, gsField):
+ return "datetime"
+
+ # ---------------------------------------------------------------------------
+ # date becomes datetime
+ # ---------------------------------------------------------------------------
+ def date (self, gsField):
+ return "smalldatetime"
+
+ # ---------------------------------------------------------------------------
+ # time becomes datetime
+ # ---------------------------------------------------------------------------
+ def time (self, gsField):
+ return "datetime"
+
+ # ---------------------------------------------------------------------------
+ # timestamp becomes datetime
+ # ---------------------------------------------------------------------------
+ def timestamp (self, gsField):
+ return "timestamp"
+
+ # ---------------------------------------------------------------------------
+ # Before starting a dump, set encoding to UTF-8
+ # ---------------------------------------------------------------------------
+ def startDump (self):
+ # self._dumpText ("\\encoding utf8\n")
+ pass
+
+
+ # ---------------------------------------------------------------------------
+ # Extend the writeTable () function with a batch-closing 'GO'
+ # ---------------------------------------------------------------------------
+ def writeTable (self, tableDef):
+ SQLProcessor.writeTable (self, tableDef)
+ self._dumpText ("GO\n\n")
+
+ # ---------------------------------------------------------------------------
+ # Extend the writeTable () function with a batch-closing 'GO'
+ # ---------------------------------------------------------------------------
+ def writeData (self, dataDef):
+ SQLProcessor.writeData (self, dataDef)
+ self._dumpText ("GO\n\n")
Property changes on: trunk/gnue-common/src/schema/scripter/processors/mssql.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/gnue-common/src/schema/scripter/processors/mysql.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/mysql.py 2004-02-12
16:06:03 UTC (rev 5105)
+++ trunk/gnue-common/src/schema/scripter/processors/mysql.py 2004-02-13
17:11:22 UTC (rev 5106)
@@ -18,7 +18,7 @@
#
# Copyright 2002-2004 Free Software Foundation
#
-# $Id: $
+# $Id$
#
from gnue.common.schema.scripter.processors.SQL import SQLProcessor
@@ -66,15 +66,21 @@
return "int unsigned"
# ---------------------------------------------------------------------------
- # text becomes either a 'string' or 'text'
+ # String
# ---------------------------------------------------------------------------
- def text (self, gsField):
+ def string (self, gsField):
if hasattr (gsField, "length") and gsField.length <= 255:
- return self.string (gsField)
+ return "varchar (%s)" % gsField.length
else:
return "text"
# ---------------------------------------------------------------------------
+ # text becomes either a 'string' or 'text'
+ # ---------------------------------------------------------------------------
+ def text (self, gsField):
+ return self.string (gsField)
+
+ # ---------------------------------------------------------------------------
# Translate a number according to it's precision and length
# ---------------------------------------------------------------------------
def number (self, gsField):
Modified: trunk/gnue-common/src/schema/scripter/processors/postgresql.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/postgresql.py
2004-02-12 16:06:03 UTC (rev 5105)
+++ trunk/gnue-common/src/schema/scripter/processors/postgresql.py
2004-02-13 17:11:22 UTC (rev 5106)
@@ -22,6 +22,7 @@
#
from gnue.common.schema.scripter.processors.SQL import SQLProcessor
+from string import join
name = "PostgreSQL"
description = "PostgreSQL (6.x/7.x)"
@@ -57,7 +58,6 @@
tableDef.fields.append (field)
-
# ===========================================================================
# Datatype translation
# ===========================================================================
@@ -69,12 +69,6 @@
return "int8"
# ---------------------------------------------------------------------------
- # Keep text as 'text'
- # ---------------------------------------------------------------------------
- def text (self, gsField):
- return "text"
-
- # ---------------------------------------------------------------------------
# A number needs special treatment
# ---------------------------------------------------------------------------
def number (self, gsField):
@@ -89,7 +83,7 @@
return "bigint"
else:
- return "decimal (%s,0)" % gsField.length
+ return "numeric (%s,0)" % gsField.length
else:
return "numeric (%s,%s)" % (gsField.length + gsField.precision,
gsField.precision)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5106 - trunk/gnue-common/src/schema/scripter/processors,
johannes <=