diff --git a/.gitignore b/.gitignore index cbfef3fe..2cecc984 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ profile.html benchmark.py results.json *.so + +.vscode/ diff --git a/orator/connectors/mssql_connector.py b/orator/connectors/mssql_connector.py new file mode 100644 index 00000000..29481f95 --- /dev/null +++ b/orator/connectors/mssql_connector.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +try: + import pyodbc +except ImportError: + pyodbc = None + connection_class = object + cursor_class = object + row_class = object + + +from ..dbal.platforms import MsSQLPlatform +from .connector import Connector +from ..utils.qmarker import qmark, denullify + +conn = pyodbc.connect('Driver={SQL Server};' + 'Server=server_name;' + 'Database=db_name;' + 'Trusted_Connection=yes;') + +cursor = conn.cursor() \ No newline at end of file diff --git a/orator/dbal/platforms/__init__.py b/orator/dbal/platforms/__init__.py index 2fe4a213..51d09628 100644 --- a/orator/dbal/platforms/__init__.py +++ b/orator/dbal/platforms/__init__.py @@ -4,3 +4,4 @@ from .mysql_platform import MySQLPlatform from .mysql57_platform import MySQL57Platform from .postgres_platform import PostgresPlatform +from .mssql_platform import MsSQLPlatform diff --git a/orator/dbal/platforms/keywords/mssql_keywords.py b/orator/dbal/platforms/keywords/mssql_keywords.py new file mode 100644 index 00000000..980312a5 --- /dev/null +++ b/orator/dbal/platforms/keywords/mssql_keywords.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- + +from .sqlserver_keywords import SQLServerKeywords + + +class MsSQLKeywords(SQLServerKeywords): + + def get_name(self): + return 'MsSQL' diff --git a/orator/dbal/platforms/keywords/sqlserver2005_keywords.py b/orator/dbal/platforms/keywords/sqlserver2005_keywords.py new file mode 100644 index 00000000..11582d60 --- /dev/null +++ b/orator/dbal/platforms/keywords/sqlserver2005_keywords.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +from .sqlserver_keywords import SQLServerKeywords + + +class SQLServer2005Keywords(SQLServerKeywords): + + # List acording to: + # http://msdn.microsoft.com/en-US/library/ms189822%28v=sql.90%29.aspx + KEYWORDS = [ + 'EXTERNAL', + 'PIVOT', + 'REVERT', + 'SECURITYAUDIT', + 'TABLESAMPLE', + 'UNPIVOT' + ] + + def get_name(self): + return 'SQLServer2005' diff --git a/orator/dbal/platforms/keywords/sqlserver2008_keywords.py b/orator/dbal/platforms/keywords/sqlserver2008_keywords.py new file mode 100644 index 00000000..42009d61 --- /dev/null +++ b/orator/dbal/platforms/keywords/sqlserver2008_keywords.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +from .sqlserver2005_keywords import SQLServer2005Keywords + + +class SQLServer2008Keywords(SQLServer2005Keywords): + + # List acording to: + # http://msdn.microsoft.com/en-us/library/ms189822%28v=sql.100%29.aspx + KEYWORDS = [ + 'MERGE' + ] + + def get_name(self): + return 'SQLServer2008' diff --git a/orator/dbal/platforms/keywords/sqlserver2012_keywords.py b/orator/dbal/platforms/keywords/sqlserver2012_keywords.py new file mode 100644 index 00000000..1b823064 --- /dev/null +++ b/orator/dbal/platforms/keywords/sqlserver2012_keywords.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +from .sqlserver2008_keywords import SQLServer2008Keywords + + +class SQLServer2012Keywords(SQLServer2008Keywords): + + # List acording to: + # http://msdn.microsoft.com/en-us/library/ms189822.aspx + KEYWORDS = [ + 'SEMANTICKEYPHRASETABLE', + 'SEMANTICSIMILARITYDETAILSTABLE', + 'SEMANTICSIMILARITYTABLE', + 'TRY_CONVERT', + 'WITHIN GROUP' + ] + + def get_name(self): + return 'SQLServer2012' diff --git a/orator/dbal/platforms/keywords/sqlserver2017_keywords.py b/orator/dbal/platforms/keywords/sqlserver2017_keywords.py new file mode 100644 index 00000000..67ab9f0b --- /dev/null +++ b/orator/dbal/platforms/keywords/sqlserver2017_keywords.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +from .sqlserver2012_keywords import SQLServer2012Keywords + + +class SQLServer2017Keywords(SQLServer2012Keywords): + + # List acording to: + # https://docs.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-server-2017 + KEYWORDS = [ + # Azure SQL Data Warehouse exclusive reserver keywords + 'LABEL' + ] + + def get_name(self): + return 'SQLServer2017' diff --git a/orator/dbal/platforms/keywords/sqlserver_keywords.py b/orator/dbal/platforms/keywords/sqlserver_keywords.py new file mode 100644 index 00000000..8db15b69 --- /dev/null +++ b/orator/dbal/platforms/keywords/sqlserver_keywords.py @@ -0,0 +1,194 @@ +# -*- coding: utf-8 -*- + +from .keyword_list import KeywordList + + +class SQLServerKeywords(KeywordList): + + # List acording to: + # http://msdn.microsoft.com/en-us/library/aa238507%28v=sql.80%29.aspx + KEYWORDS = [ + # SQL Server, Azure SQL Data Warehouse, and ODBC reserved keywords + 'ADD', + 'ALL', + 'ALTER', + 'AND', + 'ANY', + 'AS', + 'ASC', + 'AUTHORIZATION', + 'BACKUP', + 'BEGIN', + 'BETWEEN', + 'BREAK', + 'BROWSE', + 'BULK', + 'BY', + 'CASCADE', + 'CASE', + 'CHECK', + 'CHECKPOINT', + 'CLOSE', + 'CLUSTERED', + 'COALESCE', + 'COLLATE', + 'COLUMN', + 'COMMIT', + 'COMPUTE', + 'CONSTRAINT', + 'CONTAINS', + 'CONTAINSTABLE', + 'CONTINUE', + 'CONVERT', + 'CREATE', + 'CROSS', + 'CURRENT', + 'CURRENT_DATE', + 'CURRENT_TIME', + 'CURRENT_TIMESTAMP', + 'CURRENT_USER', + 'CURSOR', + 'DATABASE', + 'DBCC', + 'DEALLOCATE', + 'DECLARE', + 'DEFAULT', + 'DELETE', + 'DENY', + 'DESC', + 'DISK', + 'DISTINCT', + 'DISTRIBUTED', + 'DOUBLE', + 'DROP', + 'DUMP', + 'ELSE', + 'END', + 'ERRLVL', + 'ESCAPE', + 'EXCEPT', + 'EXEC', + 'EXECUTE', + 'EXISTS', + 'EXIT', + 'EXTERNAL', + 'FETCH', + 'FILE', + 'FILLFACTOR', + 'FOR', + 'FOREIGN', + 'FREETEXT', + 'FREETEXTTABLE', + 'FROM', + 'FULL', + 'FUNCTION', + 'GOTO', + 'GRANT', + 'GROUP', + 'HAVING', + 'HOLDLOCK', + 'IDENTITY', + 'IDENTITY_INSERT', + 'IDENTITYCOL', + 'IF', + 'IN', + 'INDEX', + 'INNER', + 'INSERT', + 'INTERSECT', + 'INTO', + 'IS', + 'JOIN', + 'KEY', + 'KILL', + 'LEFT', + 'LIKE', + 'LINENO', + 'LOAD', + 'NATIONAL', + 'NOCHECK', + 'NONCLUSTERED', + 'NOT', + 'NULL', + 'NULLIF', + 'OF', + 'OFF', + 'OFFSETS', + 'ON', + 'OPEN', + 'OPENDATASOURCE', + 'OPENQUERY', + 'OPENROWSET', + 'OPENXML', + 'OPTION', + 'OR', + 'ORDER', + 'OUTER', + 'OVER', + 'PERCENT', + 'PIVOT', + 'PLAN', + 'PRECISION', + 'PRIMARY', + 'PRINT', + 'PROC', + 'PROCEDURE', + 'PUBLIC', + 'RAISERROR', + 'READ', + 'READTEXT', + 'RECONFIGURE', + 'REFERENCES', + 'REPLICATION', + 'RESTORE', + 'RESTRICT', + 'RETURN', + 'REVERT', + 'REVOKE', + 'RIGHT', + 'ROLLBACK', + 'ROWCOUNT', + 'ROWGUIDCOL', + 'RULE', + 'SAVE', + 'SCHEMA', + 'SECURITYAUDIT', + 'SELECT', + 'SESSION_USER', + 'SET', + 'SETUSER', + 'SHUTDOWN', + 'SOME', + 'STATISTICS', + 'SYSTEM_USER', + 'TABLE', + 'TABLESAMPLE', + 'TEXTSIZE', + 'THEN', + 'TO', + 'TOP', + 'TRAN', + 'TRANSACTION', + 'TRIGGER', + 'TRUNCATE', + 'TSEQUAL', + 'UNION', + 'UNIQUE', + 'UNPIVOT', + 'UPDATE', + 'UPDATETEXT', + 'USE', + 'USER', + 'VALUES', + 'VARYING', + 'VIEW', + 'WAITFOR', + 'WHEN', + 'WHERE', + 'WHILE', + 'WITH', + 'WRITETEXT' + ] + + def get_name(self): + return 'SQLServer' diff --git a/orator/dbal/platforms/mssql_platform.py b/orator/dbal/platforms/mssql_platform.py new file mode 100644 index 00000000..7dbc363c --- /dev/null +++ b/orator/dbal/platforms/mssql_platform.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- + +from .platform import Platform +from .keywords.mssql_keywords import MsSQLKeywords +from ..identifier import Identifier + +class MsSQLPlatform(Platform): + + LENGTH_LIMIT_TINYTEXT = 255 + LENGTH_LIMIT_TEXT = 65535 + LENGTH_LIMIT_MEDIUMTEXT = 16777215 + + LENGTH_LIMIT_TINYBLOB = 255 + LENGTH_LIMIT_BLOB = 65535 + LENGTH_LIMIT_MEDIUMBLOB = 16777215 + + INTERNAL_TYPE_MAPPING = { + 'tinyint': 'tinyint', + 'smallint': 'smallint', + 'mediumint': 'int', + 'int': 'int', + 'integer': 'int', + 'bigint': 'bigint', + 'int8': 'bigint', + 'enum': 'int', + 'float': 'float', + 'double': 'float', + 'real': 'real', + 'decimal': 'decimal', + 'numeric': 'numeric', + 'bool': 'bit', + 'boolean': 'bit', + 'tinytext': 'text', + 'mediumtext': 'text', + 'longtext': 'text', + 'text': 'text', + 'varchar': 'varchar', + 'string': 'nvarchar', + 'char': 'char', + 'set': 'nvarchar', + 'date': 'date', + 'datetime': 'datetime', + 'timestamp': 'timestamp', + 'time': 'time', + 'year': 'datetime', + 'longblob': 'varbinary', + 'blob': 'varbinary', + 'mediumblob': 'varbinary', + 'tinyblob': 'varbinary', + 'binary': 'binary', + 'varbinary': 'varbinary', + } diff --git a/orator/dbal/platforms/sqlserver_platform.py b/orator/dbal/platforms/sqlserver_platform.py new file mode 100644 index 00000000..369f5ddb --- /dev/null +++ b/orator/dbal/platforms/sqlserver_platform.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +from .platform import Platform +from .keywords.sqlserver_keywords import SQLServerKeywords +from ..identifier import Identifier + +class SQLServerPlatform(Platform): + + LENGTH_LIMIT_TINYTEXT = 255 + LENGTH_LIMIT_TEXT = 65535 + LENGTH_LIMIT_MEDIUMTEXT = 16777215 + + LENGTH_LIMIT_TINYBLOB = 255 + LENGTH_LIMIT_BLOB = 65535 + LENGTH_LIMIT_MEDIUMBLOB = 16777215 + + INTERNAL_TYPE_MAPPING = { + 'bigint': 'bigint', + 'numeric': 'decimal', + 'bit': 'boolean', + 'smallint': 'smallint', + 'decimal': 'decimal', + 'smallmoney': 'integer', + 'int': 'integer', + 'tinyint': 'smallint', + 'money': 'integer', + 'float': 'float', + 'real': 'float', + 'smalldatetime': 'datetime', + 'datetime': 'datetime', + 'char': 'string', + 'varchar': 'string', + 'text': 'text', + 'nchar': 'string', + 'nvarchar': 'string', + 'ntext': 'text', + 'binary': 'binary', + 'varbinary': 'binary', + 'image': 'blob', + 'uniqueidentifier': 'guid', + 'xml': 'string', + 'date': 'date', + 'datetime2': 'datetime', + 'datetimeoffset': 'datetime', + 'time': 'time' + }