Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

SQL Server keyword/files added #325

Open
wants to merge 6 commits into
base: 0.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ profile.html
benchmark.py
results.json
*.so

.vscode/
21 changes: 21 additions & 0 deletions orator/connectors/mssql_connector.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions orator/dbal/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .mysql_platform import MySQLPlatform
from .mysql57_platform import MySQL57Platform
from .postgres_platform import PostgresPlatform
from .mssql_platform import MsSQLPlatform
9 changes: 9 additions & 0 deletions orator/dbal/platforms/keywords/mssql_keywords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

from .sqlserver_keywords import SQLServerKeywords


class MsSQLKeywords(SQLServerKeywords):

def get_name(self):
return 'MsSQL'
20 changes: 20 additions & 0 deletions orator/dbal/platforms/keywords/sqlserver2005_keywords.py
Original file line number Diff line number Diff line change
@@ -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'
15 changes: 15 additions & 0 deletions orator/dbal/platforms/keywords/sqlserver2008_keywords.py
Original file line number Diff line number Diff line change
@@ -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'
19 changes: 19 additions & 0 deletions orator/dbal/platforms/keywords/sqlserver2012_keywords.py
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 16 additions & 0 deletions orator/dbal/platforms/keywords/sqlserver2017_keywords.py
Original file line number Diff line number Diff line change
@@ -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'
194 changes: 194 additions & 0 deletions orator/dbal/platforms/keywords/sqlserver_keywords.py
Original file line number Diff line number Diff line change
@@ -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'
52 changes: 52 additions & 0 deletions orator/dbal/platforms/mssql_platform.py
Original file line number Diff line number Diff line change
@@ -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',
}
Loading