From d7bf5f991722f3109d0d274ee9a07d2b773f2fc0 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Wed, 16 Aug 2006 21:46:08 +0000 Subject: [PATCH] Initial version of the mssql generator --- .../classes/generators/mssql/mssql.class.php | 204 ++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 lib/xmldb/classes/generators/mssql/mssql.class.php diff --git a/lib/xmldb/classes/generators/mssql/mssql.class.php b/lib/xmldb/classes/generators/mssql/mssql.class.php new file mode 100644 index 0000000000..cf55554641 --- /dev/null +++ b/lib/xmldb/classes/generators/mssql/mssql.class.php @@ -0,0 +1,204 @@ +prefix = ''; + $this->reserved_words = $this->getReservedWords(); + } + + /** + * Set the prefix + */ + function setPrefix($prefix) { + $this->prefix = $prefix; + } + + /** + * Given one XMLDB Type, lenght and decimals, returns the DB proper SQL type + */ + function getTypeSQL ($xmldb_type, $xmldb_length=null, $xmldb_decimals=null) { + + switch ($xmldb_type) { + case XMLDB_TYPE_INTEGER: // From http://msdn.microsoft.com/library/en-us/tsqlref/ts_da-db_7msw.asp?frame=true + if (empty($xmldb_length)) { + $xmldb_length = 10; + } + if ($xmldb_length > 9) { + $dbtype = 'BIGINT'; + } else if ($xmldb_length > 4) { + $dbtype = 'INTEGER'; + } else { + $dbtype = 'SMALLINT'; + } + break; + case XMLDB_TYPE_NUMBER: + $dbtype = $this->number_type; + if (!empty($xmldb_length)) { + $dbtype .= '(' . $xmldb_length; + if (!empty($xmldb_decimals)) { + $dbtype .= ',' . $xmldb_decimals; + } + $dbtype .= ')'; + } + break; + case XMLDB_TYPE_FLOAT: + $dbtype = 'FLOAT'; + if (!empty($xmldb_length)) { + $dbtype .= '(' . $xmldb_length; + $dbtype .= ')'; + } + break; + case XMLDB_TYPE_CHAR: + $dbtype = 'NVARCHAR'; + if (empty($xmldb_length)) { + $xmldb_length='255'; + } + $dbtype .= '(' . $xmldb_length . ')'; + break; + case XMLDB_TYPE_TEXT: + $dbtype = 'NTEXT'; + break; + case XMLDB_TYPE_BINARY: + $dbtype = 'IMAGE'; + break; + case XMLDB_TYPE_DATETIME: + $dbtype = 'DATETIME'; + break; + } + return $dbtype; + } + + /** + * Returns the code needed to create one enum for the xmldb_table and xmldb_field passes + */ + function getEnumExtraSQL ($xmldb_table, $xmldb_field) { + + $sql = 'CONSTRAINT ' . $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck'); + $sql.= ' CHECK (' . $this->getEncQuoted($xmldb_field->getName()) . ' IN (' . implode(', ', $xmldb_field->getEnumValues()) . ')),'; + + return $sql; + } + + /** + * Returns an array of reserved words (lowercase) for this DB + */ + function getReservedWords() { + /// This file contains the reserved words for MySQL databases + /// from http://msdn.microsoft.com/library/en-us/tsqlref/ts_ra-rz_9oj7.asp + $reserved_words = array ( + 'absolute', 'action', 'ada', 'add', 'admin', 'after', 'aggregate', + 'alias', 'all', 'allocate', 'alter', 'and', 'any', 'are', 'array', 'as', + 'asc', 'assertion', 'at', 'authorization', 'avg', 'backup', 'before', + 'begin', 'between', 'binary', 'bit', 'bit_length', 'blob', 'boolean', + 'both', 'breadth', 'break', 'browse', 'bulk', 'by', 'call', 'cascade', + 'cascaded', 'case', 'cast', 'catalog', 'char', 'character', + 'character_length', 'char_length', 'check', 'checkpoint', 'class', + 'clob', 'close', 'clustered', 'coalesce', 'collate', 'collation', + 'column', 'commit', 'completion', 'compute', 'connect', + 'connection', 'constraint', 'constraints', 'constructor', 'contains', + 'containstable', 'continue', 'convert', 'corresponding', 'count', + 'create', 'cross', 'cube', 'current', 'current_date', 'current_path', + 'current_role', 'current_time', 'current_timestamp', 'current_user', + 'cursor', 'cycle', 'data', 'database', 'date', 'day', 'dbcc', 'deallocate', + 'dec', 'decimal', 'declare', 'default', 'deferrable', 'deferred', 'delete', + 'deny', 'depth', 'deref', 'desc', 'describe', 'descriptor', 'destroy', + 'destructor', 'deterministic', 'diagnostics', 'dictionary', 'disconnect', + 'disk', 'distinct', 'distributed', 'domain', 'double', 'drop', 'dummy', + 'dump', 'dynamic', 'each', 'else', 'end', 'end-exec', 'equals', 'errlvl', + 'escape', 'every', 'except', 'exception', 'exec', 'execute', 'exists', + 'exit', 'external', 'extract', 'false', 'fetch', 'file', 'fillfactor', 'first', + 'float', 'for', 'foreign', 'fortran', 'found', 'free', 'freetext', 'freetexttable', + 'from', 'full', 'function', 'general', 'get', 'global', 'go', 'goto', 'grant', + 'group', 'grouping', 'having', 'holdlock', 'host', 'hour', 'identity', + 'identitycol', 'identity_insert', 'if', 'ignore', 'immediate', 'in', + 'include', 'index', 'indicator', 'initialize', 'initially', 'inner', 'inout', + 'input', 'insensitive', 'insert', 'int', 'integer', 'intersect', 'interval', + 'into', 'is', 'isolation', 'iterate', 'join', 'key', 'kill', 'language', 'large', + 'last', 'lateral', 'leading', 'left', 'less', 'level', 'like', 'limit', 'lineno', + 'load', 'local', 'localtime', 'localtimestamp', 'locator', 'lower', 'map', + 'match', 'max', 'min', 'minute', 'modifies', 'modify', 'module', 'month', + 'names', 'national', 'natural', 'nchar', 'nclob', 'new', 'next', 'no', + 'nocheck', 'nonclustered', 'none', 'not', 'null', 'nullif', 'numeric', + 'object', 'octet_length', 'of', 'off', 'offsets', 'old', 'on', 'only', 'open', + 'opendatasource', 'openquery', 'openrowset', 'openxml', 'operation', + 'option', 'or', 'order', 'ordinality', 'out', 'outer', 'output', 'over', + 'overlaps', 'pad', 'parameter', 'parameters', 'partial', 'pascal', 'path', + 'percent', 'plan', 'position', 'postfix', 'precision', 'prefix', 'preorder', + 'prepare', 'preserve', 'primary', 'print', 'prior', 'privileges', 'proc', + 'procedure', 'public', 'raiserror', 'read', 'reads', 'readtext', 'real', + 'reconfigure', 'recursive', 'ref', 'references', 'referencing', 'relative', + 'replication', 'restore', 'restrict', 'result', 'return', 'returns', 'revoke', + 'right', 'role', 'rollback', 'rollup', 'routine', 'row', 'rowcount', 'rowguidcol', + 'rows', 'rule', 'save', 'savepoint', 'schema', 'scope', 'scroll', 'search', + 'second', 'section', 'select', 'sequence', 'session', 'session_user', 'set', + 'sets', 'setuser', 'shutdown', 'size', 'smallint', 'some', 'space', 'specific', + 'specifictype', 'sql', 'sqlca', 'sqlcode', 'sqlerror', 'sqlexception', 'sqlstate', + 'sqlwarning', 'start', 'state', 'statement', 'static', 'statistics', 'structure', + 'substring', 'sum', 'system_user', 'table', 'temporary', 'terminate', 'textsize', + 'than', 'then', 'time', 'timestamp', 'timezone_hour', 'timezone_minute', + 'to', 'top', 'trailing', 'tran', 'transaction', 'translate', 'translation', 'treat', + 'trigger', 'trim', 'true', 'truncate', 'tsequal', 'under', 'union', 'unique', + 'unknown', 'unnest', 'update', 'updatetext', 'upper', 'usage', 'use', 'user', + 'using', 'value', 'values', 'varchar', 'variable', 'varying', 'view', 'waitfor', + 'when', 'whenever', 'where', 'while', 'with', 'without', 'work', 'write', + 'writetext', 'year', 'zone' + ); + return $reserved_words; + } +} + +?> -- 2.39.5