Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_too_large(self):
"""Ensure error raised if insert fails due to truncation"""
value = 'x' * 1000
self.cursor.execute("create table t1(s varchar(800))")
def test():
self.cursor.execute("insert into t1 values (?)", value)
self.assertRaises(pyodbc.DataError, test)
def test_too_large(self):
"""Ensure error raised if insert fails due to truncation"""
value = 'x' * 1000
self.cursor.execute("create table t1(s varchar(800))")
def test():
self.cursor.execute("insert into t1 values (?)", value)
self.assertRaises(pyodbc.DataError, test)
def test_too_large(self):
"""Ensure error raised if insert fails due to truncation"""
value = 'x' * 1000
self.cursor.execute("create table t1(s varchar(800))")
def test():
self.cursor.execute("insert into t1 values (?)", value)
self.assertRaises(pyodbc.DataError, test)
assert colsize in (None, 'max') or isinstance(colsize, int), colsize
assert colsize in (None, 'max') or (value is None or colsize >= len(value))
if colsize:
sql = "create table t1(s %s(%s))" % (sqltype, colsize)
else:
sql = "create table t1(s %s)" % sqltype
self.cursor.execute(sql)
if resulttype is None:
resulttype = type(value)
sql = "insert into t1 values(?)"
try:
self.cursor.execute(sql, value)
except pyodbc.DataError:
if self.driver_type_is('freetds'):
# FREETDS_KNOWN_ISSUE
#
# cnxn.getinfo(pyodbc.SQL_DESCRIBE_PARAMETER) returns False for FreeTDS, so
# pyodbc can't call SQLDescribeParam to get the correct parameter type.
# This can lead to errors being returned from SQL Server when sp_prepexec is called,
# e.g., "Implicit conversion from data type varchar to varbinary is not allowed."
# for test_binary_null
#
# So at least verify that the user can manually specify the parameter type
if sqltype == 'varbinary':
sql_param_type = pyodbc.SQL_VARBINARY
# (add elif blocks for other cases as required)
self.cursor.setinputsizes([(sql_param_type, colsize, 0)])
self.cursor.execute(sql, value)
else:
assert colsize is None or isinstance(colsize, int), colsize
assert colsize is None or (value is None or colsize >= len(value))
if colsize:
sql = "create table t1(s %s(%s))" % (sqltype, colsize)
else:
sql = "create table t1(s %s)" % sqltype
self.cursor.execute(sql)
if resulttype is None:
resulttype = type(value)
sql = "insert into t1 values(?)"
try:
self.cursor.execute(sql, value)
except pyodbc.DataError:
if self.handle_known_issues_for('freetds'):
# FREETDS_KNOWN_ISSUE
#
# cnxn.getinfo(pyodbc.SQL_DESCRIBE_PARAMETER) returns False for FreeTDS, so
# pyodbc can't call SQLDescribeParam to get the correct parameter type.
# This can lead to errors being returned from SQL Server when sp_prepexec is called,
# e.g., "Implicit conversion from data type varchar to varbinary is not allowed."
# for test_binary_null
#
# So at least verify that the user can manually specify the parameter type
if sqltype == 'varbinary':
sql_param_type = pyodbc.SQL_VARBINARY
# (add elif blocks for other cases as required)
self.cursor.setinputsizes([(sql_param_type, colsize, 0)])
self.cursor.execute(sql, value)
else:
except ImportError:
# also requires "Oracle Instant Client"
hasOracle = False
oracleConnect = noop
oracleDatabaseError = oracleInterfaceError = NoopException
oracleCLOB = None
try:
import pyodbc
hasMSSql = True
mssqlConnect = pyodbc.connect
mssqlOperationalError = pyodbc.OperationalError
mssqlProgrammingError = pyodbc.ProgrammingError
mssqlInterfaceError = pyodbc.InterfaceError
mssqlInternalError = pyodbc.InternalError
mssqlDataError = pyodbc.DataError
mssqlIntegrityError = pyodbc.IntegrityError
except ImportError:
hasMSSql = False
mssqlConnect = noop
mssqlOperationalError = mssqlProgrammingError = mssqlInterfaceError = mssqlInternalError = \
mssqlDataError = mssqlIntegrityError = NoopException
try:
import sqlite3
hasSQLite = True
sqliteConnect = sqlite3.connect
sqliteParseDecltypes = sqlite3.PARSE_DECLTYPES
sqliteOperationalError = sqlite3.OperationalError
sqliteProgrammingError = sqlite3.ProgrammingError
sqliteInterfaceError = sqlite3.InterfaceError
sqliteInternalError = sqlite3.InternalError