Remove code specific to strings being 4000 characters now that Oracle 12c has

the ability to have strings up to 32k characters. This implies that using
setinputsizes() is necessary if a long string type is desired as this will not
occur automatically when the string exceeds 4000 characters. Tests are tidied
up to remove the "p_" prefix from all bind variables.
This commit is contained in:
Anthony Tuininga 2014-09-04 22:33:08 -06:00
parent fdde7da7f5
commit faadbe4730
21 changed files with 442 additions and 505 deletions

View File

@ -14,7 +14,7 @@ static udt_Variable *Callback_NewVariable(
void *data, // data pointer
void *indicator, // indicator pointer
ub2 *returnCode, // return code pointer
ub2 *actualLength) // actual length pointer
ACTUAL_LENGTH_TYPE *actualLength) // actual length pointer
{
udt_VariableType *type;
udt_Variable *var;
@ -67,7 +67,8 @@ static PyObject *Callback_BindByNameArgs(
va_list args) // arguments to OCI function
{
ub4 nameLength, allocatedElements, *actualElements;
ub2 dataType, *actualLength, *returnCode;
ACTUAL_LENGTH_TYPE *actualLength;
ub2 dataType, *returnCode;
dvoid *indicator, *value;
udt_Variable *var;
PyObject *result;
@ -84,7 +85,7 @@ static PyObject *Callback_BindByNameArgs(
valueLength = va_arg(args, sb4);
dataType = va_arg(args, int);
indicator = va_arg(args, dvoid*);
actualLength = va_arg(args, ub2*);
actualLength = va_arg(args, ACTUAL_LENGTH_TYPE*);
returnCode = va_arg(args, ub2*);
allocatedElements = va_arg(args, ub4);
actualElements = va_arg(args, ub4*);
@ -112,7 +113,8 @@ static PyObject *Callback_DefineByPosArgs(
udt_Connection *connection, // connection to use
va_list args) // arguments to OCI function
{
ub2 dataType, *actualLength, *returnCode;
ACTUAL_LENGTH_TYPE *actualLength;
ub2 dataType, *returnCode;
dvoid *indicator, *value;
udt_Variable *var;
PyObject *result;
@ -128,7 +130,7 @@ static PyObject *Callback_DefineByPosArgs(
valueLength = va_arg(args, sb4);
dataType = va_arg(args, int);
indicator = va_arg(args, dvoid*);
actualLength = va_arg(args, ub2*);
actualLength = va_arg(args, ACTUAL_LENGTH_TYPE*);
returnCode = va_arg(args, ub2*);
// create a variable

View File

@ -14,19 +14,12 @@ typedef struct {
int fixedWidth;
char *encoding;
char *nencoding;
ub4 maxStringBytes;
PyObject *cloneEnv;
udt_Buffer numberToStringFormatBuffer;
udt_Buffer numberFromStringFormatBuffer;
udt_Buffer nlsNumericCharactersBuffer;
} udt_Environment;
//-----------------------------------------------------------------------------
// maximum number of characters/bytes applicable to strings/binaries
//-----------------------------------------------------------------------------
#define MAX_STRING_CHARS 4000
#define MAX_BINARY_BYTES 4000
//-----------------------------------------------------------------------------
// forward declarations
//-----------------------------------------------------------------------------
@ -82,7 +75,6 @@ static udt_Environment *Environment_New(
env->errorHandle = NULL;
env->fixedWidth = 1;
env->maxBytesPerCharacter = 1;
env->maxStringBytes = MAX_STRING_CHARS;
env->cloneEnv = NULL;
cxBuffer_Init(&env->numberToStringFormatBuffer);
cxBuffer_Init(&env->numberFromStringFormatBuffer);
@ -226,7 +218,6 @@ static udt_Environment *Environment_NewFromScratch(
Py_DECREF(env);
return NULL;
}
env->maxStringBytes = MAX_STRING_CHARS * env->maxBytesPerCharacter;
// acquire whether character set is fixed width
status = OCINlsNumericInfoGet(env->handle, env->errorHandle,
@ -275,7 +266,6 @@ static udt_Environment *Environment_Clone(
if (!env)
return NULL;
env->maxBytesPerCharacter = cloneEnv->maxBytesPerCharacter;
env->maxStringBytes = cloneEnv->maxStringBytes;
env->fixedWidth = cloneEnv->fixedWidth;
Py_INCREF(cloneEnv);
env->cloneEnv = (PyObject*) cloneEnv;

View File

@ -190,7 +190,7 @@ static udt_VariableType vt_String = {
&g_StringVarType, // Python type
SQLT_CHR, // Oracle type
SQLCS_IMPLICIT, // charset form
MAX_STRING_CHARS, // element length (default)
4000, // element length (default)
1, // is character data
1, // is variable length
1, // can be copied
@ -211,7 +211,7 @@ static udt_VariableType vt_NationalCharString = {
&g_UnicodeVarType, // Python type
SQLT_CHR, // Oracle type
SQLCS_NCHAR, // charset form
MAX_STRING_CHARS, // element length (default)
4000, // element length (default)
1, // is character data
1, // is variable length
1, // can be copied
@ -295,7 +295,7 @@ static udt_VariableType vt_Binary = {
&g_BinaryVarType, // Python type
SQLT_BIN, // Oracle type
SQLCS_IMPLICIT, // charset form
MAX_BINARY_BYTES, // element length (default)
4000, // element length (default)
0, // is character data
1, // is variable length
1, // can be copied
@ -311,12 +311,18 @@ static int StringVar_Initialize(
udt_StringVar *var, // variable to initialize
udt_Cursor *cursor) // cursor to use
{
var->actualLength = (ub2*) PyMem_Malloc(var->allocatedElements *
sizeof(ub2));
ub4 i;
var->actualLength = (ACTUAL_LENGTH_TYPE *)
PyMem_Malloc(var->allocatedElements * sizeof(ACTUAL_LENGTH_TYPE));
if (!var->actualLength) {
PyErr_NoMemory();
return -1;
}
for (i = 0; i < var->allocatedElements; i++)
var->actualLength[i] = 0;
return 0;
}
@ -335,17 +341,6 @@ static int StringVar_SetValue(
// populate the buffer and confirm the maximum size is not exceeded
if (cxBuffer_FromObject(&buffer, value, var->environment->encoding) < 0)
return -1;
if (var->type->isCharacterData
&& buffer.numCharacters > MAX_STRING_CHARS) {
cxBuffer_Clear(&buffer);
PyErr_SetString(PyExc_ValueError, "string data too large");
return -1;
} else if (!var->type->isCharacterData
&& buffer.size > MAX_BINARY_BYTES) {
cxBuffer_Clear(&buffer);
PyErr_SetString(PyExc_ValueError, "binary data too large");
return -1;
}
// ensure that the buffer is large enough
if (buffer.size > var->bufferSize) {
@ -356,7 +351,7 @@ static int StringVar_SetValue(
}
// keep a copy of the string
var->actualLength[pos] = (ub2) buffer.size;
var->actualLength[pos] = (ACTUAL_LENGTH_TYPE) buffer.size;
if (buffer.size)
memcpy(var->data + var->bufferSize * pos, buffer.ptr, buffer.size);
cxBuffer_Clear(&buffer);

View File

@ -6,6 +6,18 @@
//-----------------------------------------------------------------------------
// define structure common to all variables
//-----------------------------------------------------------------------------
#if ORACLE_VERSION_HEX >= ORACLE_VERSION(12,1)
#define OCIBINDBYNAME OCIBindByName2
#define OCIBINDBYPOS OCIBindByPos2
#define OCIDEFINEBYPOS OCIDefineByPos2
#define ACTUAL_LENGTH_TYPE ub4
#else
#define OCIBINDBYNAME OCIBindByName
#define OCIBINDBYPOS OCIBindByPos
#define OCIDEFINEBYPOS OCIDefineByPos
#define ACTUAL_LENGTH_TYPE ub2
#endif
struct _udt_VariableType;
#define Variable_HEAD \
PyObject_HEAD \
@ -24,7 +36,7 @@ struct _udt_VariableType;
int isAllocatedInternally; \
sb2 *indicator; \
ub2 *returnCode; \
ub2 *actualLength; \
ACTUAL_LENGTH_TYPE *actualLength; \
ub4 size; \
ub4 bufferSize; \
struct _udt_VariableType *type;
@ -484,15 +496,11 @@ static udt_VariableType *Variable_TypeByValue(
}
if (cxString_Check(value)) {
*size = cxString_GetSize(value);
if (*size > MAX_STRING_CHARS)
return &vt_LongString;
return &vt_String;
}
#if PY_MAJOR_VERSION < 3
if (PyUnicode_Check(value)) {
*size = PyUnicode_GET_SIZE(value);
if (*size > MAX_STRING_CHARS)
return &vt_LongNationalCharString;
return &vt_NationalCharString;
}
if (PyInt_Check(value))
@ -500,8 +508,6 @@ static udt_VariableType *Variable_TypeByValue(
#else
if (PyBytes_Check(value)) {
*size = PyBytes_GET_SIZE(value);
if (*size > MAX_BINARY_BYTES)
return &vt_LongBinary;
return &vt_Binary;
}
#endif
@ -517,8 +523,6 @@ static udt_VariableType *Variable_TypeByValue(
return NULL;
*size = temp.size;
cxBuffer_Clear(&temp);
if (*size > MAX_BINARY_BYTES)
return &vt_LongBinary;
return &vt_Binary;
}
if (PyDateTime_Check(value))
@ -824,9 +828,7 @@ static udt_Variable *Variable_NewByType(
size = PyInt_AsLong(value);
if (PyErr_Occurred())
return NULL;
if (size > MAX_STRING_CHARS)
varType = &vt_LongString;
else varType = &vt_String;
varType = &vt_String;
return Variable_New(cursor, numElements, varType, size);
}
@ -993,7 +995,7 @@ static udt_Variable *Variable_DefineHelper(
}
// perform the define
status = OCIDefineByPos(cursor->handle, &var->defineHandle,
status = OCIDEFINEBYPOS(cursor->handle, &var->defineHandle,
var->environment->errorHandle, position, var->data,
var->bufferSize, var->type->oracleType, var->indicator,
var->actualLength, var->returnCode, OCI_DEFAULT);
@ -1058,14 +1060,14 @@ static int Variable_InternalBind(
var->environment->encoding) < 0)
return -1;
if (var->isArray) {
status = OCIBindByName(var->boundCursorHandle, &var->bindHandle,
status = OCIBINDBYNAME(var->boundCursorHandle, &var->bindHandle,
var->environment->errorHandle, (text*) buffer.ptr,
buffer.size, var->data, var->bufferSize,
var->type->oracleType, var->indicator, var->actualLength,
var->returnCode, var->allocatedElements,
&var->actualElements, OCI_DEFAULT);
} else {
status = OCIBindByName(var->boundCursorHandle, &var->bindHandle,
status = OCIBINDBYNAME(var->boundCursorHandle, &var->bindHandle,
var->environment->errorHandle, (text*) buffer.ptr,
buffer.size, var->data, var->bufferSize,
var->type->oracleType, var->indicator, var->actualLength,
@ -1074,13 +1076,13 @@ static int Variable_InternalBind(
cxBuffer_Clear(&buffer);
} else {
if (var->isArray) {
status = OCIBindByPos(var->boundCursorHandle, &var->bindHandle,
status = OCIBINDBYPOS(var->boundCursorHandle, &var->bindHandle,
var->environment->errorHandle, var->boundPos, var->data,
var->bufferSize, var->type->oracleType, var->indicator,
var->actualLength, var->returnCode, var->allocatedElements,
&var->actualElements, OCI_DEFAULT);
} else {
status = OCIBindByPos(var->boundCursorHandle, &var->bindHandle,
status = OCIBINDBYPOS(var->boundCursorHandle, &var->bindHandle,
var->environment->errorHandle, var->boundPos, var->data,
var->bufferSize, var->type->oracleType, var->indicator,
var->actualLength, var->returnCode, 0, 0, OCI_DEFAULT);

View File

@ -83,33 +83,33 @@ class TestNumberVar(BaseTestCase):
array = [r[1] for r in self.rawData]
statement = """
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_StartValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:startValue, :array);
end;"""
self.cursor.execute(statement,
p_ReturnValue = returnValue,
p_StartValue = 5,
p_Array = array)
returnValue = returnValue,
startValue = 5,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 73.75)
array = list(range(15))
self.cursor.execute(statement,
p_StartValue = 10,
p_Array = array)
startValue = 10,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 115.0)
def testBindNumberArrayBySizes(self):
"test binding in a number array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.NUMBER, 10])
self.cursor.setinputsizes(array = [cx_Oracle.NUMBER, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_StartValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:startValue, :array);
end;""",
p_ReturnValue = returnValue,
p_StartValue = 6,
p_Array = array)
returnValue = returnValue,
startValue = 6,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 74.75)
def testBindNumberArrayByVar(self):
@ -120,12 +120,12 @@ class TestNumberVar(BaseTestCase):
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 7,
p_Array = array)
returnValue = returnValue,
integerValue = 7,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 75.75)
def testBindZeroLengthNumberArrayByVar(self):
@ -134,12 +134,12 @@ class TestNumberVar(BaseTestCase):
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 0)
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 8,
p_Array = array)
returnValue = returnValue,
integerValue = 8,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 8.0)
self.failUnlessEqual(array.getvalue(), [])
@ -152,10 +152,10 @@ class TestNumberVar(BaseTestCase):
array.setvalue(0, originalData)
self.cursor.execute("""
begin
pkg_TestNumberArrays.TestInOutArrays(:p_NumElems, :p_Array);
pkg_TestNumberArrays.TestInOutArrays(:numElems, :array);
end;""",
p_NumElems = 5,
p_Array = array)
numElems = 5,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutNumberArrayByVar(self):
@ -164,10 +164,10 @@ class TestNumberVar(BaseTestCase):
expectedData = [i * 100 for i in range(1, 7)]
self.cursor.execute("""
begin
pkg_TestNumberArrays.TestOutArrays(:p_NumElems, :p_Array);
pkg_TestNumberArrays.TestOutArrays(:numElems, :array);
end;""",
p_NumElems = 6,
p_Array = array)
numElems = 6,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutSetInputSizes(self):

View File

@ -22,8 +22,8 @@ class TestStringVar(BaseTestCase):
"test binding in a string"
self.cursor.execute("""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = "String 5")
where StringCol = :value""",
value = "String 5")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindDifferentVar(self):
@ -39,11 +39,11 @@ class TestStringVar(BaseTestCase):
def testBindStringAfterNumber(self):
"test binding in a string after setting input sizes to a number"
self.cursor.setinputsizes(p_Value = cx_Oracle.NUMBER)
self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
self.cursor.execute("""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = "String 6")
where StringCol = :value""",
value = "String 6")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[6]])
def testBindStringArrayDirect(self):
@ -52,33 +52,33 @@ class TestStringVar(BaseTestCase):
array = [r[1] for r in self.rawData]
statement = """
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestStringArrays.TestInArrays(
:integerValue, :array);
end;"""
self.cursor.execute(statement,
p_ReturnValue = returnValue,
p_IntegerValue = 5,
p_Array = array)
returnValue = returnValue,
integerValue = 5,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 86)
array = [ "String - %d" % i for i in range(15) ]
self.cursor.execute(statement,
p_IntegerValue = 8,
p_Array = array)
integerValue = 8,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 163)
def testBindStringArrayBySizes(self):
"test binding in a string array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.STRING, 10])
self.cursor.setinputsizes(array = [cx_Oracle.STRING, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestStringArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 6,
p_Array = array)
returnValue = returnValue,
integerValue = 6,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 87)
def testBindStringArrayByVar(self):
@ -88,12 +88,12 @@ class TestStringVar(BaseTestCase):
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestStringArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 7,
p_Array = array)
returnValue = returnValue,
integerValue = 7,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 88)
def testBindInOutStringArrayByVar(self):
@ -106,10 +106,10 @@ class TestStringVar(BaseTestCase):
array.setvalue(0, originalData)
self.cursor.execute("""
begin
pkg_TestStringArrays.TestInOutArrays(:p_NumElems, :p_Array);
pkg_TestStringArrays.TestInOutArrays(:numElems, :array);
end;""",
p_NumElems = 5,
p_Array = array)
numElems = 5,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutStringArrayByVar(self):
@ -118,19 +118,19 @@ class TestStringVar(BaseTestCase):
expectedData = ["Test out element # %d" % i for i in range(1, 7)]
self.cursor.execute("""
begin
pkg_TestStringArrays.TestOutArrays(:p_NumElems, :p_Array);
pkg_TestStringArrays.TestOutArrays(:numElems, :array);
end;""",
p_NumElems = 6,
p_Array = array)
numElems = 6,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindRaw(self):
"test binding in a raw"
self.cursor.setinputsizes(p_Value = cx_Oracle.BINARY)
self.cursor.setinputsizes(value = cx_Oracle.BINARY)
self.cursor.execute("""
select * from TestStrings
where RawCol = :p_Value""",
p_Value = b"Raw 4")
where RawCol = :value""",
value = b"Raw 4")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindAndFetchRowid(self):
@ -143,64 +143,64 @@ class TestStringVar(BaseTestCase):
self.cursor.execute("""
select *
from TestStrings
where rowid = :p_Value""",
p_Value = rowid)
where rowid = :value""",
value = rowid)
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[3]])
def testBindNull(self):
"test binding in a null"
self.cursor.execute("""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = None)
where StringCol = :value""",
value = None)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizesByType(self):
"test binding out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.STRING)
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
self.cursor.execute("""
begin
:p_Value := 'TSI';
:value := 'TSI';
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(), "TSI")
self.failUnlessEqual(vars["value"].getvalue(), "TSI")
def testBindOutSetInputSizesByInteger(self):
"test binding out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(p_Value = 30)
vars = self.cursor.setinputsizes(value = 30)
self.cursor.execute("""
begin
:p_Value := 'TSI (I)';
:value := 'TSI (I)';
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(), "TSI (I)")
self.failUnlessEqual(vars["value"].getvalue(), "TSI (I)")
def testBindInOutSetInputSizesByType(self):
"test binding in/out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.STRING)
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
self.cursor.execute("""
begin
:p_Value := :p_Value || ' TSI';
:value := :value || ' TSI';
end;""",
p_Value = "InVal")
self.failUnlessEqual(vars["p_Value"].getvalue(), "InVal TSI")
value = "InVal")
self.failUnlessEqual(vars["value"].getvalue(), "InVal TSI")
def testBindInOutSetInputSizesByInteger(self):
"test binding in/out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(p_Value = 30)
vars = self.cursor.setinputsizes(value = 30)
self.cursor.execute("""
begin
:p_Value := :p_Value || ' TSI (I)';
:value := :value || ' TSI (I)';
end;""",
p_Value = "InVal")
self.failUnlessEqual(vars["p_Value"].getvalue(), "InVal TSI (I)")
value = "InVal")
self.failUnlessEqual(vars["value"].getvalue(), "InVal TSI (I)")
def testBindOutVar(self):
"test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.STRING)
self.cursor.execute("""
begin
:p_Value := 'TSI (VAR)';
:value := 'TSI (VAR)';
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(), "TSI (VAR)")
def testBindInOutVarDirectSet(self):
@ -209,13 +209,14 @@ class TestStringVar(BaseTestCase):
var.setvalue(0, "InVal")
self.cursor.execute("""
begin
:p_Value := :p_Value || ' TSI (VAR)';
:value := :value || ' TSI (VAR)';
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(), "InVal TSI (VAR)")
def testBindLongString(self):
"test that binding a long string succeeds"
self.cursor.setinputsizes(bigString = cx_Oracle.LONG_STRING)
self.cursor.execute("""
declare
t_Temp varchar2(10000);
@ -227,7 +228,6 @@ class TestStringVar(BaseTestCase):
def testBindLongStringAfterSettingSize(self):
"test that setinputsizes() returns a long variable"
var = self.cursor.setinputsizes(test = 90000)["test"]
self.failUnlessEqual(type(var), cx_Oracle.LONG_STRING)
inString = "1234567890" * 9000
var.setvalue(0, inString)
outString = var.getvalue()
@ -235,19 +235,6 @@ class TestStringVar(BaseTestCase):
"output does not match: in was %d, out was %d" % \
(len(inString), len(outString)))
def testStringMaximumReached(self):
"test that an error is raised when maximum string length exceeded"
var = self.cursor.setinputsizes(test = 100)["test"]
inString = "1234567890" * 400
var.setvalue(0, inString)
outString = var.getvalue()
self.failUnlessEqual(inString, outString,
"output does not match: in was %d, out was %d" % \
(len(inString), len(outString)))
badStringSize = 4000 * self.connection.maxBytesPerCharacter + 1
inString = "X" * badStringSize
self.failUnlessRaises(ValueError, var.setvalue, 0, inString)
def testCursorDescription(self):
"test cursor description is accurate"
self.cursor.execute("select * from TestStrings")

View File

@ -27,25 +27,25 @@ class TestCursor(BaseTestCase):
def testExecuteKeywordArgs(self):
"""test executing a statement with keyword arguments"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
result = self.cursor.execute("begin :p_Value := 5; end;",
p_Value = simpleVar)
result = self.cursor.execute("begin :value := 5; end;",
value = simpleVar)
self.failUnlessEqual(result, None)
self.failUnlessEqual(simpleVar.getvalue(), 5)
def testExecuteDictionaryArg(self):
"""test executing a statement with a dictionary argument"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
dictArg = { "p_Value" : simpleVar }
result = self.cursor.execute("begin :p_Value := 10; end;", dictArg)
dictArg = { "value" : simpleVar }
result = self.cursor.execute("begin :value := 10; end;", dictArg)
self.failUnlessEqual(result, None)
self.failUnlessEqual(simpleVar.getvalue(), 10)
def testExecuteMultipleMethod(self):
"""test executing a statement with both a dict arg and keyword args"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
dictArg = { "p_Value" : simpleVar }
dictArg = { "value" : simpleVar }
self.failUnlessRaises(cx_Oracle.InterfaceError, self.cursor.execute,
"begin :p_Value := 15; end;", dictArg, p_Value = simpleVar)
"begin :value := 15; end;", dictArg, value = simpleVar)
def testExecuteAndModifyArraySize(self):
"""test executing a statement and then changing the array size"""
@ -149,8 +149,8 @@ class TestCursor(BaseTestCase):
def testExecuteManyWithExecption(self):
"""test executing a statement multiple times (with exception)"""
self.cursor.execute("truncate table TestExecuteMany")
rows = [ { "p_Value" : n } for n in (1, 2, 3, 2, 5) ]
statement = "insert into TestExecuteMany (IntCol) values (:p_Value)"
rows = [ { "value" : n } for n in (1, 2, 3, 2, 5) ]
statement = "insert into TestExecuteMany (IntCol) values (:value)"
self.failUnlessRaises(cx_Oracle.DatabaseError, self.cursor.executemany,
statement, rows)
self.failUnlessEqual(self.cursor.rowcount, 3)
@ -158,16 +158,16 @@ class TestCursor(BaseTestCase):
def testPrepare(self):
"""test preparing a statement and executing it multiple times"""
self.failUnlessEqual(self.cursor.statement, None)
statement = "begin :p_Value := :p_Value + 5; end;"
statement = "begin :value := :value + 5; end;"
self.cursor.prepare(statement)
var = self.cursor.var(cx_Oracle.NUMBER)
self.failUnlessEqual(self.cursor.statement, statement)
var.setvalue(0, 2)
self.cursor.execute(None, p_Value = var)
self.cursor.execute(None, value = var)
self.failUnlessEqual(var.getvalue(), 7)
self.cursor.execute(None, p_Value = var)
self.cursor.execute(None, value = var)
self.failUnlessEqual(var.getvalue(), 12)
self.cursor.execute("begin :p_Value2 := 3; end;", p_Value2 = var)
self.cursor.execute("begin :value2 := 3; end;", value2 = var)
self.failUnlessEqual(var.getvalue(), 3)
def testExceptionOnClose(self):

View File

@ -11,9 +11,9 @@ class TestCursorVar(BaseTestCase):
self.failUnlessEqual(cursor.description, None)
self.cursor.execute("""
begin
open :p_Cursor for select 'X' StringValue from dual;
open :cursor for select 'X' StringValue from dual;
end;""",
p_Cursor = cursor)
cursor = cursor)
self.failUnlessEqual(cursor.description,
[ ('STRINGVALUE', cx_Oracle.FIXED_CHAR, 1, 1, 0, 0, 1) ])
self.failUnlessEqual(cursor.fetchall(), [('X',)])

View File

@ -27,8 +27,8 @@ class TestDateTimeVar(BaseTestCase):
"test binding in a date"
self.cursor.execute("""
select * from TestDates
where DateCol = :p_Value""",
p_Value = cx_Oracle.Timestamp(2002, 12, 13, 9, 36, 0))
where DateCol = :value""",
value = cx_Oracle.Timestamp(2002, 12, 13, 9, 36, 0))
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindDateTime(self):
@ -41,20 +41,20 @@ class TestDateTimeVar(BaseTestCase):
def testBindDateAfterString(self):
"test binding in a date after setting input sizes to a string"
self.cursor.setinputsizes(p_Value = 15)
self.cursor.setinputsizes(value = 15)
self.cursor.execute("""
select * from TestDates
where DateCol = :p_Value""",
p_Value = cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
where DateCol = :value""",
value = cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindNull(self):
"test binding in a null"
self.cursor.setinputsizes(p_Value = cx_Oracle.DATETIME)
self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
self.cursor.execute("""
select * from TestDates
where DateCol = :p_Value""",
p_Value = None)
where DateCol = :value""",
value = None)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testBindDateArrayDirect(self):
@ -63,36 +63,36 @@ class TestDateTimeVar(BaseTestCase):
array = [r[1] for r in self.rawData]
statement = """
begin
:p_ReturnValue := pkg_TestDateArrays.TestInArrays(
:p_StartValue, :p_BaseDate, :p_Array);
:returnValue := pkg_TestDateArrays.TestInArrays(
:startValue, :baseDate, :array);
end;"""
self.cursor.execute(statement,
p_ReturnValue = returnValue,
p_StartValue = 5,
p_BaseDate = cx_Oracle.Date(2002, 12, 12),
p_Array = array)
returnValue = returnValue,
startValue = 5,
baseDate = cx_Oracle.Date(2002, 12, 12),
array = array)
self.failUnlessEqual(returnValue.getvalue(), 35.5)
array = array + array[:5]
self.cursor.execute(statement,
p_StartValue = 7,
p_BaseDate = cx_Oracle.Date(2002, 12, 13),
p_Array = array)
startValue = 7,
baseDate = cx_Oracle.Date(2002, 12, 13),
array = array)
self.failUnlessEqual(returnValue.getvalue(), 24.0)
def testBindDateArrayBySizes(self):
"test binding in a date array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.DATETIME, 10])
self.cursor.setinputsizes(array = [cx_Oracle.DATETIME, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestDateArrays.TestInArrays(
:p_StartValue, :p_BaseDate, :p_Array);
:returnValue := pkg_TestDateArrays.TestInArrays(
:startValue, :baseDate, :array);
end;""",
p_ReturnValue = returnValue,
p_StartValue = 6,
p_BaseDate = cx_Oracle.Date(2002, 12, 13),
p_Array = array)
returnValue = returnValue,
startValue = 6,
baseDate = cx_Oracle.Date(2002, 12, 13),
array = array)
self.failUnlessEqual(returnValue.getvalue(), 26.5)
def testBindDateArrayByVar(self):
@ -102,13 +102,13 @@ class TestDateTimeVar(BaseTestCase):
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestDateArrays.TestInArrays(
:p_StartValue, :p_BaseDate, :p_Array);
:returnValue := pkg_TestDateArrays.TestInArrays(
:startValue, :baseDate, :array);
end;""",
p_ReturnValue = returnValue,
p_StartValue = 7,
p_BaseDate = cx_Oracle.Date(2002, 12, 14),
p_Array = array)
returnValue = returnValue,
startValue = 7,
baseDate = cx_Oracle.Date(2002, 12, 14),
array = array)
self.failUnlessEqual(returnValue.getvalue(), 17.5)
def testBindInOutDateArrayByVar(self):
@ -118,10 +118,10 @@ class TestDateTimeVar(BaseTestCase):
array.setvalue(0, originalData)
self.cursor.execute("""
begin
pkg_TestDateArrays.TestInOutArrays(:p_NumElems, :p_Array);
pkg_TestDateArrays.TestInOutArrays(:numElems, :array);
end;""",
p_NumElems = 5,
p_Array = array)
numElems = 5,
array = array)
self.failUnlessEqual(array.getvalue(),
[ cx_Oracle.Timestamp(2002, 12, 17, 2, 24, 0),
cx_Oracle.Timestamp(2002, 12, 18, 4, 48, 0),
@ -135,10 +135,10 @@ class TestDateTimeVar(BaseTestCase):
array = self.cursor.arrayvar(cx_Oracle.DATETIME, 6, 100)
self.cursor.execute("""
begin
pkg_TestDateArrays.TestOutArrays(:p_NumElems, :p_Array);
pkg_TestDateArrays.TestOutArrays(:numElems, :array);
end;""",
p_NumElems = 6,
p_Array = array)
numElems = 6,
array = array)
self.failUnlessEqual(array.getvalue(),
[ cx_Oracle.Timestamp(2002, 12, 13, 4, 48, 0),
cx_Oracle.Timestamp(2002, 12, 14, 9, 36, 0),
@ -149,23 +149,23 @@ class TestDateTimeVar(BaseTestCase):
def testBindOutSetInputSizes(self):
"test binding out with set input sizes defined"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.DATETIME)
vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
self.cursor.execute("""
begin
:p_Value := to_date(20021209, 'YYYYMMDD');
:value := to_date(20021209, 'YYYYMMDD');
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(),
self.failUnlessEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 9))
def testBindInOutSetInputSizes(self):
"test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.DATETIME)
vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
self.cursor.execute("""
begin
:p_Value := :p_Value + 5.25;
:value := :value + 5.25;
end;""",
p_Value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
self.failUnlessEqual(vars["p_Value"].getvalue(),
value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
self.failUnlessEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0))
def testBindOutVar(self):
@ -173,10 +173,10 @@ class TestDateTimeVar(BaseTestCase):
var = self.cursor.var(cx_Oracle.DATETIME)
self.cursor.execute("""
begin
:p_Value := to_date('20021231 12:31:00',
:value := to_date('20021231 12:31:00',
'YYYYMMDD HH24:MI:SS');
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0))
@ -186,9 +186,9 @@ class TestDateTimeVar(BaseTestCase):
var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0))
self.cursor.execute("""
begin
:p_Value := :p_Value + 5.25;
:value := :value + 5.25;
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))

View File

@ -10,7 +10,7 @@ class TestLongVar(BaseTestCase):
for i in range(1, 11):
char = chr(ord('A') + i - 1)
longString += char * 25000
self.cursor.setinputsizes(p_LongString = a_InputType)
self.cursor.setinputsizes(longString = a_InputType)
if a_Type == "LongRaw" and sys.version_info[0] >= 3:
bindValue = longString.encode("ascii")
else:
@ -20,11 +20,11 @@ class TestLongVar(BaseTestCase):
IntCol,
%sCol
) values (
:p_IntegerValue,
:p_LongString
:integerValue,
:longString
)""" % (a_Type, a_Type),
p_IntegerValue = i,
p_LongString = bindValue)
integerValue = i,
longString = bindValue)
self.connection.commit()
self.cursor.setoutputsize(250000, 2)
self.cursor.execute("""

View File

@ -91,33 +91,33 @@ class TestNumberVar(BaseTestCase):
array = [r[1] for r in self.rawData]
statement = """
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_StartValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:startValue, :array);
end;"""
self.cursor.execute(statement,
p_ReturnValue = returnValue,
p_StartValue = 5,
p_Array = array)
returnValue = returnValue,
startValue = 5,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 73.75)
array = range(15)
self.cursor.execute(statement,
p_StartValue = 10,
p_Array = array)
startValue = 10,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 115.0)
def testBindNumberArrayBySizes(self):
"test binding in a number array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.NUMBER, 10])
self.cursor.setinputsizes(array = [cx_Oracle.NUMBER, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_StartValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:startValue, :array);
end;""",
p_ReturnValue = returnValue,
p_StartValue = 6,
p_Array = array)
returnValue = returnValue,
startValue = 6,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 74.75)
def testBindNumberArrayByVar(self):
@ -128,12 +128,12 @@ class TestNumberVar(BaseTestCase):
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 7,
p_Array = array)
returnValue = returnValue,
integerValue = 7,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 75.75)
def testBindZeroLengthNumberArrayByVar(self):
@ -142,12 +142,12 @@ class TestNumberVar(BaseTestCase):
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 0)
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 8,
p_Array = array)
returnValue = returnValue,
integerValue = 8,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 8.0)
self.failUnlessEqual(array.getvalue(), [])
@ -160,10 +160,10 @@ class TestNumberVar(BaseTestCase):
array.setvalue(0, originalData)
self.cursor.execute("""
begin
pkg_TestNumberArrays.TestInOutArrays(:p_NumElems, :p_Array);
pkg_TestNumberArrays.TestInOutArrays(:numElems, :array);
end;""",
p_NumElems = 5,
p_Array = array)
numElems = 5,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutNumberArrayByVar(self):
@ -172,10 +172,10 @@ class TestNumberVar(BaseTestCase):
expectedData = [i * 100 for i in range(1, 7)]
self.cursor.execute("""
begin
pkg_TestNumberArrays.TestOutArrays(:p_NumElems, :p_Array);
pkg_TestNumberArrays.TestOutArrays(:numElems, :array);
end;""",
p_NumElems = 6,
p_Array = array)
numElems = 6,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutSetInputSizes(self):

View File

@ -22,8 +22,8 @@ class TestStringVar(BaseTestCase):
"test binding in a string"
self.cursor.execute("""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = "String 5")
where StringCol = :value""",
value = "String 5")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindDifferentVar(self):
@ -39,11 +39,11 @@ class TestStringVar(BaseTestCase):
def testBindStringAfterNumber(self):
"test binding in a string after setting input sizes to a number"
self.cursor.setinputsizes(p_Value = cx_Oracle.NUMBER)
self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
self.cursor.execute("""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = "String 6")
where StringCol = :value""",
value = "String 6")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[6]])
def testBindStringArrayDirect(self):
@ -52,33 +52,33 @@ class TestStringVar(BaseTestCase):
array = [r[1] for r in self.rawData]
statement = """
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestStringArrays.TestInArrays(
:integerValue, :array);
end;"""
self.cursor.execute(statement,
p_ReturnValue = returnValue,
p_IntegerValue = 5,
p_Array = array)
returnValue = returnValue,
integerValue = 5,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 86)
array = [ "String - %d" % i for i in range(15) ]
self.cursor.execute(statement,
p_IntegerValue = 8,
p_Array = array)
integerValue = 8,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 163)
def testBindStringArrayBySizes(self):
"test binding in a string array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.STRING, 10])
self.cursor.setinputsizes(array = [cx_Oracle.STRING, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestStringArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 6,
p_Array = array)
returnValue = returnValue,
integerValue = 6,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 87)
def testBindStringArrayByVar(self):
@ -88,12 +88,12 @@ class TestStringVar(BaseTestCase):
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute("""
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestStringArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 7,
p_Array = array)
returnValue = returnValue,
integerValue = 7,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 88)
def testBindInOutStringArrayByVar(self):
@ -106,10 +106,10 @@ class TestStringVar(BaseTestCase):
array.setvalue(0, originalData)
self.cursor.execute("""
begin
pkg_TestStringArrays.TestInOutArrays(:p_NumElems, :p_Array);
pkg_TestStringArrays.TestInOutArrays(:numElems, :array);
end;""",
p_NumElems = 5,
p_Array = array)
numElems = 5,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutStringArrayByVar(self):
@ -118,19 +118,19 @@ class TestStringVar(BaseTestCase):
expectedData = ["Test out element # %d" % i for i in range(1, 7)]
self.cursor.execute("""
begin
pkg_TestStringArrays.TestOutArrays(:p_NumElems, :p_Array);
pkg_TestStringArrays.TestOutArrays(:numElems, :array);
end;""",
p_NumElems = 6,
p_Array = array)
numElems = 6,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindRaw(self):
"test binding in a raw"
self.cursor.setinputsizes(p_Value = cx_Oracle.BINARY)
self.cursor.setinputsizes(value = cx_Oracle.BINARY)
self.cursor.execute("""
select * from TestStrings
where RawCol = :p_Value""",
p_Value = "Raw 4")
where RawCol = :value""",
value = "Raw 4")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindAndFetchRowid(self):
@ -143,64 +143,64 @@ class TestStringVar(BaseTestCase):
self.cursor.execute("""
select *
from TestStrings
where rowid = :p_Value""",
p_Value = rowid)
where rowid = :value""",
value = rowid)
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[3]])
def testBindNull(self):
"test binding in a null"
self.cursor.execute("""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = None)
where StringCol = :value""",
value = None)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizesByType(self):
"test binding out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.STRING)
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
self.cursor.execute("""
begin
:p_Value := 'TSI';
:value := 'TSI';
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(), "TSI")
self.failUnlessEqual(vars["value"].getvalue(), "TSI")
def testBindOutSetInputSizesByInteger(self):
"test binding out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(p_Value = 30)
vars = self.cursor.setinputsizes(value = 30)
self.cursor.execute("""
begin
:p_Value := 'TSI (I)';
:value := 'TSI (I)';
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(), "TSI (I)")
self.failUnlessEqual(vars["value"].getvalue(), "TSI (I)")
def testBindInOutSetInputSizesByType(self):
"test binding in/out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.STRING)
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
self.cursor.execute("""
begin
:p_Value := :p_Value || ' TSI';
:value := :value || ' TSI';
end;""",
p_Value = "InVal")
self.failUnlessEqual(vars["p_Value"].getvalue(), "InVal TSI")
value = "InVal")
self.failUnlessEqual(vars["value"].getvalue(), "InVal TSI")
def testBindInOutSetInputSizesByInteger(self):
"test binding in/out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(p_Value = 30)
vars = self.cursor.setinputsizes(value = 30)
self.cursor.execute("""
begin
:p_Value := :p_Value || ' TSI (I)';
:value := :value || ' TSI (I)';
end;""",
p_Value = "InVal")
self.failUnlessEqual(vars["p_Value"].getvalue(), "InVal TSI (I)")
value = "InVal")
self.failUnlessEqual(vars["value"].getvalue(), "InVal TSI (I)")
def testBindOutVar(self):
"test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.STRING)
self.cursor.execute("""
begin
:p_Value := 'TSI (VAR)';
:value := 'TSI (VAR)';
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(), "TSI (VAR)")
def testBindInOutVarDirectSet(self):
@ -209,13 +209,14 @@ class TestStringVar(BaseTestCase):
var.setvalue(0, "InVal")
self.cursor.execute("""
begin
:p_Value := :p_Value || ' TSI (VAR)';
:value := :value || ' TSI (VAR)';
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(), "InVal TSI (VAR)")
def testBindLongString(self):
"test that binding a long string succeeds"
self.cursor.setinputsizes(bigString = cx_Oracle.LONG_STRING)
self.cursor.execute("""
declare
t_Temp varchar2(10000);
@ -227,7 +228,6 @@ class TestStringVar(BaseTestCase):
def testBindLongStringAfterSettingSize(self):
"test that setinputsizes() returns a long variable"
var = self.cursor.setinputsizes(test = 90000)["test"]
self.failUnlessEqual(type(var), cx_Oracle.LONG_STRING)
inString = "1234567890" * 9000
var.setvalue(0, inString)
outString = var.getvalue()
@ -235,19 +235,6 @@ class TestStringVar(BaseTestCase):
"output does not match: in was %d, out was %d" % \
(len(inString), len(outString)))
def testStringMaximumReached(self):
"test that an error is raised when maximum string length exceeded"
var = self.cursor.setinputsizes(test = 100)["test"]
inString = "1234567890" * 400
var.setvalue(0, inString)
outString = var.getvalue()
self.failUnlessEqual(inString, outString,
"output does not match: in was %d, out was %d" % \
(len(inString), len(outString)))
badStringSize = 4000 * self.connection.maxBytesPerCharacter + 1
inString = "X" * badStringSize
self.failUnlessRaises(ValueError, var.setvalue, 0, inString)
def testCursorDescription(self):
"test cursor description is accurate"
self.cursor.execute("select * from TestStrings")

View File

@ -42,32 +42,32 @@ class TestTimestampVar(BaseTestCase):
def testBindNull(self):
"test binding in a null"
self.cursor.setinputsizes(p_Value = cx_Oracle.TIMESTAMP)
self.cursor.setinputsizes(value = cx_Oracle.TIMESTAMP)
self.cursor.execute("""
select * from TestTimestamps
where TimestampCol = :p_Value""",
p_Value = None)
where TimestampCol = :value""",
value = None)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizes(self):
"test binding out with set input sizes defined"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.TIMESTAMP)
vars = self.cursor.setinputsizes(value = cx_Oracle.TIMESTAMP)
self.cursor.execute("""
begin
:p_Value := to_timestamp('20021209', 'YYYYMMDD');
:value := to_timestamp('20021209', 'YYYYMMDD');
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(),
self.failUnlessEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 9))
def testBindInOutSetInputSizes(self):
"test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.TIMESTAMP)
vars = self.cursor.setinputsizes(value = cx_Oracle.TIMESTAMP)
self.cursor.execute("""
begin
:p_Value := :p_Value + 5.25;
:value := :value + 5.25;
end;""",
p_Value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
self.failUnlessEqual(vars["p_Value"].getvalue(),
value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
self.failUnlessEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0))
def testBindOutVar(self):
@ -75,10 +75,10 @@ class TestTimestampVar(BaseTestCase):
var = self.cursor.var(cx_Oracle.TIMESTAMP)
self.cursor.execute("""
begin
:p_Value := to_date('20021231 12:31:00',
:value := to_date('20021231 12:31:00',
'YYYYMMDD HH24:MI:SS');
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0))
@ -88,9 +88,9 @@ class TestTimestampVar(BaseTestCase):
var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0))
self.cursor.execute("""
begin
:p_Value := :p_Value + 5.25;
:value := :value + 5.25;
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))

View File

@ -184,18 +184,6 @@ class TestUnicodeVar(BaseTestCase):
value = var)
self.failUnlessEqual(var.getvalue(), u"InVal \u3041 TSI (VAR) \u3042")
def testUnicodeMaximumReached(self):
"test that an error is raised when maximum unicode length exceeded"
var = self.cursor.setinputsizes(test = cx_Oracle.UNICODE)["test"]
inUnicode = u"1234567890" * 400
var.setvalue(0, inUnicode)
outUnicode = var.getvalue()
self.failUnlessEqual(inUnicode, outUnicode,
"output does not match: in was %d, out was %d" % \
(len(inUnicode), len(outUnicode)))
inUnicode = inUnicode + u"0"
self.failUnlessRaises(ValueError, var.setvalue, 0, inUnicode)
def testCursorDescription(self):
"test cursor description is accurate"
self.cursor.execute("select * from TestUnicodes")

View File

@ -26,25 +26,25 @@ class TestCursor(BaseTestCase):
def testExecuteKeywordArgs(self):
"""test executing a statement with keyword arguments"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
result = self.cursor.execute(u"begin :p_Value := 5; end;",
p_Value = simpleVar)
result = self.cursor.execute(u"begin :value := 5; end;",
value = simpleVar)
self.failUnlessEqual(result, None)
self.failUnlessEqual(simpleVar.getvalue(), 5)
def testExecuteDictionaryArg(self):
"""test executing a statement with a dictionary argument"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
dictArg = { u"p_Value" : simpleVar }
result = self.cursor.execute(u"begin :p_Value := 10; end;", dictArg)
dictArg = { u"value" : simpleVar }
result = self.cursor.execute(u"begin :value := 10; end;", dictArg)
self.failUnlessEqual(result, None)
self.failUnlessEqual(simpleVar.getvalue(), 10)
def testExecuteMultipleMethod(self):
"""test executing a statement with both a dict arg and keyword args"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
dictArg = { u"p_Value" : simpleVar }
dictArg = { u"value" : simpleVar }
self.failUnlessRaises(cx_Oracle.InterfaceError, self.cursor.execute,
u"begin :p_Value := 15; end;", dictArg, p_Value = simpleVar)
u"begin :value := 15; end;", dictArg, value = simpleVar)
def testExecuteAndModifyArraySize(self):
"""test executing a statement and then changing the array size"""
@ -127,8 +127,8 @@ class TestCursor(BaseTestCase):
def testExecuteManyWithExecption(self):
"""test executing a statement multiple times (with exception)"""
self.cursor.execute(u"truncate table TestExecuteMany")
rows = [ { u"p_Value" : n } for n in (1, 2, 3, 2, 5) ]
statement = u"insert into TestExecuteMany (IntCol) values (:p_Value)"
rows = [ { u"value" : n } for n in (1, 2, 3, 2, 5) ]
statement = u"insert into TestExecuteMany (IntCol) values (:value)"
self.failUnlessRaises(cx_Oracle.DatabaseError, self.cursor.executemany,
statement, rows)
self.failUnlessEqual(self.cursor.rowcount, 3)
@ -136,16 +136,16 @@ class TestCursor(BaseTestCase):
def testPrepare(self):
"""test preparing a statement and executing it multiple times"""
self.failUnlessEqual(self.cursor.statement, None)
statement = u"begin :p_Value := :p_Value + 5; end;"
statement = u"begin :value := :value + 5; end;"
self.cursor.prepare(statement)
var = self.cursor.var(cx_Oracle.NUMBER)
self.failUnlessEqual(self.cursor.statement, statement)
var.setvalue(0, 2)
self.cursor.execute(None, p_Value = var)
self.cursor.execute(None, value = var)
self.failUnlessEqual(var.getvalue(), 7)
self.cursor.execute(None, p_Value = var)
self.cursor.execute(None, value = var)
self.failUnlessEqual(var.getvalue(), 12)
self.cursor.execute(u"begin :p_Value2 := 3; end;", p_Value2 = var)
self.cursor.execute(u"begin :value2 := 3; end;", value2 = var)
self.failUnlessEqual(var.getvalue(), 3)
def testExceptionOnClose(self):

View File

@ -11,9 +11,9 @@ class TestCursorVar(BaseTestCase):
self.failUnlessEqual(cursor.description, None)
self.cursor.execute(u"""
begin
open :p_Cursor for select 'X' StringValue from dual;
open :cursor for select 'X' StringValue from dual;
end;""",
p_Cursor = cursor)
cursor = cursor)
self.failUnlessEqual(cursor.description,
[ ('STRINGVALUE', cx_Oracle.FIXED_CHAR, 1, 1, 0, 0, 1) ])
self.failUnlessEqual(cursor.fetchall(), [('X',)])

View File

@ -27,8 +27,8 @@ class TestDateTimeVar(BaseTestCase):
"test binding in a date"
self.cursor.execute(u"""
select * from TestDates
where DateCol = :p_Value""",
p_Value = cx_Oracle.Timestamp(2002, 12, 13, 9, 36, 0))
where DateCol = :value""",
value = cx_Oracle.Timestamp(2002, 12, 13, 9, 36, 0))
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindDateTime(self):
@ -41,20 +41,20 @@ class TestDateTimeVar(BaseTestCase):
def testBindDateAfterString(self):
"test binding in a date after setting input sizes to a string"
self.cursor.setinputsizes(p_Value = 15)
self.cursor.setinputsizes(value = 15)
self.cursor.execute(u"""
select * from TestDates
where DateCol = :p_Value""",
p_Value = cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
where DateCol = :value""",
value = cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindNull(self):
"test binding in a null"
self.cursor.setinputsizes(p_Value = cx_Oracle.DATETIME)
self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
self.cursor.execute(u"""
select * from TestDates
where DateCol = :p_Value""",
p_Value = None)
where DateCol = :value""",
value = None)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testBindDateArrayDirect(self):
@ -63,36 +63,36 @@ class TestDateTimeVar(BaseTestCase):
array = [r[1] for r in self.rawData]
statement = u"""
begin
:p_ReturnValue := pkg_TestDateArrays.TestInArrays(
:p_StartValue, :p_BaseDate, :p_Array);
:returnValue := pkg_TestDateArrays.TestInArrays(
:startValue, :baseDate, :array);
end;"""
self.cursor.execute(statement,
p_ReturnValue = returnValue,
p_StartValue = 5,
p_BaseDate = cx_Oracle.Date(2002, 12, 12),
p_Array = array)
returnValue = returnValue,
startValue = 5,
baseDate = cx_Oracle.Date(2002, 12, 12),
array = array)
self.failUnlessEqual(returnValue.getvalue(), 35.5)
array = array + array[:5]
self.cursor.execute(statement,
p_StartValue = 7,
p_BaseDate = cx_Oracle.Date(2002, 12, 13),
p_Array = array)
startValue = 7,
baseDate = cx_Oracle.Date(2002, 12, 13),
array = array)
self.failUnlessEqual(returnValue.getvalue(), 24.0)
def testBindDateArrayBySizes(self):
"test binding in a date array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.DATETIME, 10])
self.cursor.setinputsizes(array = [cx_Oracle.DATETIME, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute(u"""
begin
:p_ReturnValue := pkg_TestDateArrays.TestInArrays(
:p_StartValue, :p_BaseDate, :p_Array);
:returnValue := pkg_TestDateArrays.TestInArrays(
:startValue, :baseDate, :array);
end;""",
p_ReturnValue = returnValue,
p_StartValue = 6,
p_BaseDate = cx_Oracle.Date(2002, 12, 13),
p_Array = array)
returnValue = returnValue,
startValue = 6,
baseDate = cx_Oracle.Date(2002, 12, 13),
array = array)
self.failUnlessEqual(returnValue.getvalue(), 26.5)
def testBindDateArrayByVar(self):
@ -102,13 +102,13 @@ class TestDateTimeVar(BaseTestCase):
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute(u"""
begin
:p_ReturnValue := pkg_TestDateArrays.TestInArrays(
:p_StartValue, :p_BaseDate, :p_Array);
:returnValue := pkg_TestDateArrays.TestInArrays(
:startValue, :baseDate, :array);
end;""",
p_ReturnValue = returnValue,
p_StartValue = 7,
p_BaseDate = cx_Oracle.Date(2002, 12, 14),
p_Array = array)
returnValue = returnValue,
startValue = 7,
baseDate = cx_Oracle.Date(2002, 12, 14),
array = array)
self.failUnlessEqual(returnValue.getvalue(), 17.5)
def testBindInOutDateArrayByVar(self):
@ -118,10 +118,10 @@ class TestDateTimeVar(BaseTestCase):
array.setvalue(0, originalData)
self.cursor.execute(u"""
begin
pkg_TestDateArrays.TestInOutArrays(:p_NumElems, :p_Array);
pkg_TestDateArrays.TestInOutArrays(:numElems, :array);
end;""",
p_NumElems = 5,
p_Array = array)
numElems = 5,
array = array)
self.failUnlessEqual(array.getvalue(),
[ cx_Oracle.Timestamp(2002, 12, 17, 2, 24, 0),
cx_Oracle.Timestamp(2002, 12, 18, 4, 48, 0),
@ -135,10 +135,10 @@ class TestDateTimeVar(BaseTestCase):
array = self.cursor.arrayvar(cx_Oracle.DATETIME, 6, 100)
self.cursor.execute(u"""
begin
pkg_TestDateArrays.TestOutArrays(:p_NumElems, :p_Array);
pkg_TestDateArrays.TestOutArrays(:numElems, :array);
end;""",
p_NumElems = 6,
p_Array = array)
numElems = 6,
array = array)
self.failUnlessEqual(array.getvalue(),
[ cx_Oracle.Timestamp(2002, 12, 13, 4, 48, 0),
cx_Oracle.Timestamp(2002, 12, 14, 9, 36, 0),
@ -149,23 +149,23 @@ class TestDateTimeVar(BaseTestCase):
def testBindOutSetInputSizes(self):
"test binding out with set input sizes defined"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.DATETIME)
vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
self.cursor.execute(u"""
begin
:p_Value := to_date(20021209, 'YYYYMMDD');
:value := to_date(20021209, 'YYYYMMDD');
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(),
self.failUnlessEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 9))
def testBindInOutSetInputSizes(self):
"test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.DATETIME)
vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
self.cursor.execute(u"""
begin
:p_Value := :p_Value + 5.25;
:value := :value + 5.25;
end;""",
p_Value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
self.failUnlessEqual(vars["p_Value"].getvalue(),
value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
self.failUnlessEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0))
def testBindOutVar(self):
@ -173,10 +173,10 @@ class TestDateTimeVar(BaseTestCase):
var = self.cursor.var(cx_Oracle.DATETIME)
self.cursor.execute(u"""
begin
:p_Value := to_date('20021231 12:31:00',
:value := to_date('20021231 12:31:00',
'YYYYMMDD HH24:MI:SS');
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0))
@ -186,9 +186,9 @@ class TestDateTimeVar(BaseTestCase):
var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0))
self.cursor.execute(u"""
begin
:p_Value := :p_Value + 5.25;
:value := :value + 5.25;
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))

View File

@ -14,17 +14,17 @@ class TestLongVar(BaseTestCase):
else:
char = chr(ord('A') + i - 1)
longString += char * 25000
self.cursor.setinputsizes(p_LongString = a_InputType)
self.cursor.setinputsizes(longString = a_InputType)
self.cursor.execute(u"""
insert into Test%ss (
IntCol,
%sCol
) values (
:p_IntegerValue,
:p_LongString
:integerValue,
:longString
)""" % (a_Type, a_Type),
p_IntegerValue = i,
p_LongString = longString)
integerValue = i,
longString = longString)
self.connection.commit()
self.cursor.setoutputsize(250000, 2)
self.cursor.execute(u"""

View File

@ -91,33 +91,33 @@ class TestNumberVar(BaseTestCase):
array = [r[1] for r in self.rawData]
statement = u"""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_StartValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:startValue, :array);
end;"""
self.cursor.execute(statement,
p_ReturnValue = returnValue,
p_StartValue = 5,
p_Array = array)
returnValue = returnValue,
startValue = 5,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 73.75)
array = range(15)
self.cursor.execute(statement,
p_StartValue = 10,
p_Array = array)
startValue = 10,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 115.0)
def testBindNumberArrayBySizes(self):
"test binding in a number array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.NUMBER, 10])
self.cursor.setinputsizes(array = [cx_Oracle.NUMBER, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute(u"""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_StartValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:startValue, :array);
end;""",
p_ReturnValue = returnValue,
p_StartValue = 6,
p_Array = array)
returnValue = returnValue,
startValue = 6,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 74.75)
def testBindNumberArrayByVar(self):
@ -128,12 +128,12 @@ class TestNumberVar(BaseTestCase):
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute(u"""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 7,
p_Array = array)
returnValue = returnValue,
integerValue = 7,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 75.75)
def testBindZeroLengthNumberArrayByVar(self):
@ -142,12 +142,12 @@ class TestNumberVar(BaseTestCase):
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 0)
self.cursor.execute(u"""
begin
:p_ReturnValue := pkg_TestNumberArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestNumberArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 8,
p_Array = array)
returnValue = returnValue,
integerValue = 8,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 8.0)
self.failUnlessEqual(array.getvalue(), [])
@ -160,10 +160,10 @@ class TestNumberVar(BaseTestCase):
array.setvalue(0, originalData)
self.cursor.execute(u"""
begin
pkg_TestNumberArrays.TestInOutArrays(:p_NumElems, :p_Array);
pkg_TestNumberArrays.TestInOutArrays(:numElems, :array);
end;""",
p_NumElems = 5,
p_Array = array)
numElems = 5,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutNumberArrayByVar(self):
@ -172,10 +172,10 @@ class TestNumberVar(BaseTestCase):
expectedData = [i * 100 for i in range(1, 7)]
self.cursor.execute(u"""
begin
pkg_TestNumberArrays.TestOutArrays(:p_NumElems, :p_Array);
pkg_TestNumberArrays.TestOutArrays(:numElems, :array);
end;""",
p_NumElems = 6,
p_Array = array)
numElems = 6,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutSetInputSizes(self):

View File

@ -22,8 +22,8 @@ class TestStringVar(BaseTestCase):
"test binding in a string"
self.cursor.execute(u"""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = u"String 5")
where StringCol = :value""",
value = u"String 5")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[5]])
def testBindDifferentVar(self):
@ -39,26 +39,26 @@ class TestStringVar(BaseTestCase):
def testBindStringAfterNumber(self):
"test binding in a string after setting input sizes to a number"
self.cursor.setinputsizes(p_Value = cx_Oracle.NUMBER)
self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
self.cursor.execute(u"""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = u"String 6")
where StringCol = :value""",
value = u"String 6")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[6]])
def testBindStringArrayBySizes(self):
"test binding in a string array (with setinputsizes)"
returnValue = self.cursor.var(cx_Oracle.NUMBER)
self.cursor.setinputsizes(p_Array = [cx_Oracle.STRING, 10])
self.cursor.setinputsizes(array = [cx_Oracle.STRING, 10])
array = [r[1] for r in self.rawData]
self.cursor.execute(u"""
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestStringArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 6,
p_Array = array)
returnValue = returnValue,
integerValue = 6,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 87)
def testBindStringArrayByVar(self):
@ -68,12 +68,12 @@ class TestStringVar(BaseTestCase):
array.setvalue(0, [r[1] for r in self.rawData])
self.cursor.execute(u"""
begin
:p_ReturnValue := pkg_TestStringArrays.TestInArrays(
:p_IntegerValue, :p_Array);
:returnValue := pkg_TestStringArrays.TestInArrays(
:integerValue, :array);
end;""",
p_ReturnValue = returnValue,
p_IntegerValue = 7,
p_Array = array)
returnValue = returnValue,
integerValue = 7,
array = array)
self.failUnlessEqual(returnValue.getvalue(), 88)
def testBindInOutStringArrayByVar(self):
@ -86,10 +86,10 @@ class TestStringVar(BaseTestCase):
array.setvalue(0, originalData)
self.cursor.execute(u"""
begin
pkg_TestStringArrays.TestInOutArrays(:p_NumElems, :p_Array);
pkg_TestStringArrays.TestInOutArrays(:numElems, :array);
end;""",
p_NumElems = 5,
p_Array = array)
numElems = 5,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindOutStringArrayByVar(self):
@ -98,19 +98,19 @@ class TestStringVar(BaseTestCase):
expectedData = [u"Test out element # %d" % i for i in range(1, 7)]
self.cursor.execute(u"""
begin
pkg_TestStringArrays.TestOutArrays(:p_NumElems, :p_Array);
pkg_TestStringArrays.TestOutArrays(:numElems, :array);
end;""",
p_NumElems = 6,
p_Array = array)
numElems = 6,
array = array)
self.failUnlessEqual(array.getvalue(), expectedData)
def testBindRaw(self):
"test binding in a raw"
self.cursor.setinputsizes(p_Value = cx_Oracle.BINARY)
self.cursor.setinputsizes(value = cx_Oracle.BINARY)
self.cursor.execute(u"""
select * from TestStrings
where RawCol = :p_Value""",
p_Value = "Raw 4")
where RawCol = :value""",
value = "Raw 4")
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindAndFetchRowid(self):
@ -123,64 +123,64 @@ class TestStringVar(BaseTestCase):
self.cursor.execute(u"""
select *
from TestStrings
where rowid = :p_Value""",
p_Value = rowid)
where rowid = :value""",
value = rowid)
self.failUnlessEqual(self.cursor.fetchall(), [self.dataByKey[3]])
def testBindNull(self):
"test binding in a null"
self.cursor.execute(u"""
select * from TestStrings
where StringCol = :p_Value""",
p_Value = None)
where StringCol = :value""",
value = None)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizesByType(self):
"test binding out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.STRING)
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
self.cursor.execute(u"""
begin
:p_Value := 'TSI';
:value := 'TSI';
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(), u"TSI")
self.failUnlessEqual(vars["value"].getvalue(), u"TSI")
def testBindOutSetInputSizesByInteger(self):
"test binding out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(p_Value = 30)
vars = self.cursor.setinputsizes(value = 30)
self.cursor.execute(u"""
begin
:p_Value := 'TSI (I)';
:value := 'TSI (I)';
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(), u"TSI (I)")
self.failUnlessEqual(vars["value"].getvalue(), u"TSI (I)")
def testBindInOutSetInputSizesByType(self):
"test binding in/out with set input sizes defined (by type)"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.STRING)
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
self.cursor.execute(u"""
begin
:p_Value := :p_Value || ' TSI';
:value := :value || ' TSI';
end;""",
p_Value = u"InVal")
self.failUnlessEqual(vars["p_Value"].getvalue(), u"InVal TSI")
value = u"InVal")
self.failUnlessEqual(vars["value"].getvalue(), u"InVal TSI")
def testBindInOutSetInputSizesByInteger(self):
"test binding in/out with set input sizes defined (by integer)"
vars = self.cursor.setinputsizes(p_Value = 30)
vars = self.cursor.setinputsizes(value = 30)
self.cursor.execute(u"""
begin
:p_Value := :p_Value || ' TSI (I)';
:value := :value || ' TSI (I)';
end;""",
p_Value = u"InVal")
self.failUnlessEqual(vars["p_Value"].getvalue(), u"InVal TSI (I)")
value = u"InVal")
self.failUnlessEqual(vars["value"].getvalue(), u"InVal TSI (I)")
def testBindOutVar(self):
"test binding out with cursor.var() method"
var = self.cursor.var(cx_Oracle.STRING)
self.cursor.execute(u"""
begin
:p_Value := 'TSI (VAR)';
:value := 'TSI (VAR)';
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(), u"TSI (VAR)")
def testBindInOutVarDirectSet(self):
@ -189,9 +189,9 @@ class TestStringVar(BaseTestCase):
var.setvalue(0, u"InVal")
self.cursor.execute(u"""
begin
:p_Value := :p_Value || ' TSI (VAR)';
:value := :value || ' TSI (VAR)';
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(), u"InVal TSI (VAR)")
def testBindLongString(self):
@ -207,7 +207,6 @@ class TestStringVar(BaseTestCase):
def testBindLongStringAfterSettingSize(self):
"test that setinputsizes() returns a long variable"
var = self.cursor.setinputsizes(test = 90000)["test"]
self.failUnlessEqual(type(var), cx_Oracle.LONG_STRING)
inString = u"1234567890" * 9000
var.setvalue(0, inString)
outString = var.getvalue()
@ -215,19 +214,6 @@ class TestStringVar(BaseTestCase):
"output does not match: in was %d, out was %d" % \
(len(inString), len(outString)))
def testStringMaximumReached(self):
"test that an error is raised when maximum string length exceeded"
var = self.cursor.setinputsizes(test = 100)["test"]
inString = u"1234567890" * 400
var.setvalue(0, inString)
outString = var.getvalue()
self.failUnlessEqual(inString, outString,
"output does not match: in was %d, out was %d" % \
(len(inString), len(outString)))
badStringSize = 4001
inString = u"X" * badStringSize
self.failUnlessRaises(ValueError, var.setvalue, 0, inString)
def testCursorDescription(self):
"test cursor description is accurate"
self.cursor.execute(u"select * from TestStrings")

View File

@ -42,32 +42,32 @@ class TestTimestampVar(BaseTestCase):
def testBindNull(self):
"test binding in a null"
self.cursor.setinputsizes(p_Value = cx_Oracle.TIMESTAMP)
self.cursor.setinputsizes(value = cx_Oracle.TIMESTAMP)
self.cursor.execute(u"""
select * from TestTimestamps
where TimestampCol = :p_Value""",
p_Value = None)
where TimestampCol = :value""",
value = None)
self.failUnlessEqual(self.cursor.fetchall(), [])
def testBindOutSetInputSizes(self):
"test binding out with set input sizes defined"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.TIMESTAMP)
vars = self.cursor.setinputsizes(value = cx_Oracle.TIMESTAMP)
self.cursor.execute(u"""
begin
:p_Value := to_timestamp('20021209', 'YYYYMMDD');
:value := to_timestamp('20021209', 'YYYYMMDD');
end;""")
self.failUnlessEqual(vars["p_Value"].getvalue(),
self.failUnlessEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 9))
def testBindInOutSetInputSizes(self):
"test binding in/out with set input sizes defined"
vars = self.cursor.setinputsizes(p_Value = cx_Oracle.TIMESTAMP)
vars = self.cursor.setinputsizes(value = cx_Oracle.TIMESTAMP)
self.cursor.execute(u"""
begin
:p_Value := :p_Value + 5.25;
:value := :value + 5.25;
end;""",
p_Value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
self.failUnlessEqual(vars["p_Value"].getvalue(),
value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
self.failUnlessEqual(vars["value"].getvalue(),
cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0))
def testBindOutVar(self):
@ -75,10 +75,10 @@ class TestTimestampVar(BaseTestCase):
var = self.cursor.var(cx_Oracle.TIMESTAMP)
self.cursor.execute(u"""
begin
:p_Value := to_date('20021231 12:31:00',
:value := to_date('20021231 12:31:00',
'YYYYMMDD HH24:MI:SS');
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0))
@ -88,9 +88,9 @@ class TestTimestampVar(BaseTestCase):
var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0))
self.cursor.execute(u"""
begin
:p_Value := :p_Value + 5.25;
:value := :value + 5.25;
end;""",
p_Value = var)
value = var)
self.failUnlessEqual(var.getvalue(),
cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))