Commit 5d1f153e authored by Timothy Smith's avatar Timothy Smith

Import the ibmdb2i-ga4-src snapshot from IBM

parent 858d40d8
......@@ -65,6 +65,11 @@ class ProtectedBuffer
len = size;
if (protectBuf)
mprotect(protectedPage(), 0x1000, PROT_NONE);
#ifndef DBUG_OFF
// Prevents a problem with DBUG_PRINT over-reading in recent versions of
// MySQL
*((char*)protectedPage()-1) = 0;
#endif
}
}
......
......@@ -703,7 +703,7 @@ static int32 openNewConversion(enum_conversionDirection direction,
*/
int32 getConversion(enum_conversionDirection direction, const CHARSET_INFO* cs, uint16 db2CCSID, iconv_t& conversion)
{
DBUG_ENTER("db2i_charsetSupport::convChars");
DBUG_ENTER("db2i_charsetSupport::getConversion");
int32 rc;
......
......@@ -277,33 +277,32 @@ static int32 getAssociatedSortSequence(const CHARSET_INFO *fieldCharSet, const c
This function accumulates information about a key as it is called for each
field composing the key. The caller should invoke the function for each field
and (with the exception of the curField parm) preserve the values for the
and (with the exception of the charset parm) preserve the values for the
parms across invocations, until a particular key has been evaluated. Once
the last field in the key has been evaluated, the fileSortSequence and
fileSortSequenceLibrary parms will contain the correct information for
creating the corresponding DB2 key.
@param curField The field under consideration
@param charset The character set under consideration
@param[in, out] fileSortSequenceType The type of the current key's sort seq
@param[in, out] fileSortSequence The IBM i identifier for the DB2 sort sequence
that corresponds
@return 0 if successful. Failure otherwise
*/
int32 updateAssociatedSortSequence(const Field *curField,
int32 updateAssociatedSortSequence(const CHARSET_INFO* charset,
char* fileSortSequenceType,
char* fileSortSequence,
char* fileSortSequenceLibrary)
{
DBUG_ENTER("ha_ibmdb2i::updateAssociatedSortSequence");
DBUG_ASSERT(curField);
CHARSET_INFO* fieldCharSet = curField->charset();
if (strcmp(fieldCharSet->csname,"binary") != 0)
DBUG_ASSERT(charset);
if (strcmp(charset->csname,"binary") != 0)
{
char newSortSequence[11] = "";
char newSortSequenceType = ' ';
const char* foundSortSequence;
int rc = getAssociatedSortSequence(fieldCharSet, &foundSortSequence);
int rc = getAssociatedSortSequence(charset, &foundSortSequence);
if (rc) DBUG_RETURN (rc);
switch(foundSortSequence[0])
{
......@@ -313,11 +312,11 @@ int32 updateAssociatedSortSequence(const Field *curField,
break;
case 'Q': // Non-ICU sort sequence
strcat(newSortSequence,foundSortSequence);
if ((fieldCharSet->state & MY_CS_BINSORT) != 0)
if ((charset->state & MY_CS_BINSORT) != 0)
{
strcat(newSortSequence,"U");
}
else if ((fieldCharSet->state & MY_CS_CSSORT) != 0)
else if ((charset->state & MY_CS_CSSORT) != 0)
{
strcat(newSortSequence,"U");
}
......@@ -329,7 +328,7 @@ int32 updateAssociatedSortSequence(const Field *curField,
break;
default: // ICU sort sequence
{
if ((fieldCharSet->state & MY_CS_CSSORT) == 0)
if ((charset->state & MY_CS_CSSORT) == 0)
{
if (osVersion.v >= 6)
strcat(newSortSequence,"I34"); // ICU 3.4
......
......@@ -40,6 +40,9 @@ OF SUCH DAMAGE.
#include "db2i_global.h"
#include "mysql_priv.h"
int32 updateAssociatedSortSequence(const Field *curField, char* fileSortSequenceType, char* fileSortSequence, char* fileSortSequenceLibrary);
int32 updateAssociatedSortSequence(const CHARSET_INFO* charset,
char* fileSortSequenceType,
char* fileSortSequence,
char* fileSortSequenceLibrary);
#endif
......@@ -150,7 +150,7 @@ int ha_ibmdb2i::buildDB2ConstraintString(LEX* lex,
{
if (strcmp((*field)->field_name, curColumn->field_name) == 0)
{
int rc = updateAssociatedSortSequence((*field),
int rc = updateAssociatedSortSequence((*field)->charset(),
fileSortSequenceType,
fileSortSequence,
fileSortSequenceLibrary);
......@@ -447,14 +447,13 @@ int ha_ibmdb2i::get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_lis
cst_name* fieldName; // Pointer to field name structure
const char *method;
ulong methodLen;
bool gotShare = FALSE; // Indicator for local get_share
char* tempPtr; // Temp pointer for traversing constraint space
char convName[128];
// Allocate space to retrieve the DB2 constraint information.
if (!(share = get_share(table_share->path.str, table)))
DBUG_RETURN(0);
// Allocate space to retrieve the DB2 constraint information.
constraintSpaceLength = 5000; // Try allocating 5000 bytes and see if enough.
constraintSpace.alloc(constraintSpaceLength);
......
This diff is collapsed.
......@@ -63,9 +63,9 @@ static const char* engineErrors[MAX_MSGSTRING] =
{"Error in iconv() function during character set conversion (errno = %d)"},
{"Error from Get Encoding Scheme (QTQGESP) API: %d, %d, %d"},
{"Error from Get Related Default CCSID (QTQGRDC) API: %d, %d, %d"},
{"Invalid value '%-.128s' for column '%.192s'"},
{"Data out of range for column '%.192s'"},
{"Schema name '%.128s' exceeds maximum length of %d characters"},
{"Multiple collations not supported in a single index"},
{"Multiple collations not supported in a single index or constraint"},
{"Sort sequence was not found"},
{"One or more characters in column %.128s were substituted during conversion"},
{"A decimal column exceeded the maximum precision. Data may be truncated."},
......@@ -76,6 +76,7 @@ static const char* engineErrors[MAX_MSGSTRING] =
{"A duplicate key was encountered for index '%.128s'"},
{"A table with the same name exists but has incompatible column definitions."},
{"The created table was discovered as an existing DB2 object."},
{"Some attribute(s) defined for column '%.128s' may not be honored by accesses from DB2."},
};
/*
......
......@@ -78,7 +78,8 @@ enum DB2I_errors
DB2I_ERR_UNKNOWN_IDX,
DB2I_ERR_DISCOVERY_MISMATCH,
DB2I_ERR_WARN_CREATE_DISCOVER,
DB2I_LAST_ERR = DB2I_ERR_WARN_CREATE_DISCOVER
DB2I_ERR_WARN_COL_ATTRS,
DB2I_LAST_ERR = DB2I_ERR_WARN_COL_ATTRS
};
void getErrTxt(int errcode, ...);
......@@ -86,6 +87,7 @@ void reportSystemAPIError(int errCode, const Qmy_Error_output *errInfo);
void warning(THD *thd, int errCode, ...);
const char* DB2I_SQL0350 = "\xE2\xD8\xD3\xF0\xF3\xF5\xF0"; // SQL0350 in EBCDIC
const char* DB2I_CPF503A = "\xC3\xD7\xC6\xF5\xF0\xF3\xC1"; // CPF503A in EBCDIC
const char* DB2I_SQL0538 = "\xE2\xD8\xD3\xF0\xF5\xF3\xF8"; // SQL0538 in EBCDIC
#endif
......@@ -96,11 +96,12 @@ int32 db2i_table::initDB2Objects(const char* path)
physicalFile = new db2i_file(this);
physicalFile->fillILEDefn(&fileDefnSpace[0], true);
if (fileObjects > 1)
logicalFileCount = mysqlTable->keys;
if (logicalFileCount > 0)
{
logicalFiles = new db2i_file*[fileObjects - 1];
for (int k = 0; k < mysqlTable->keys; k++)
logicalFiles = new db2i_file*[logicalFileCount];
for (int k = 0; k < logicalFileCount; k++)
{
logicalFiles[k] = new db2i_file(this, k);
logicalFiles[k]->fillILEDefn(&fileDefnSpace[k+1], false);
......@@ -111,16 +112,29 @@ int32 db2i_table::initDB2Objects(const char* path)
size_t formatSpaceLen = sizeof(format_hdr_t) + mysqlTable->fields * sizeof(DB2Field);
formatSpace.alloc(formatSpaceLen);
int rc = db2i_ileBridge::getBridgeForThread()->allocateFileDefn(fileDefnSpace,
fileDefnHandles,
fileObjects,
db2LibNameEbcdic,
strlen(db2LibNameEbcdic),
formatSpace,
formatSpaceLen);
int rc = db2i_ileBridge::getBridgeForThread()->
expectErrors(QMY_ERR_RTNFMT)->
allocateFileDefn(fileDefnSpace,
fileDefnHandles,
fileObjects,
db2LibNameEbcdic,
strlen(db2LibNameEbcdic),
formatSpace,
formatSpaceLen);
if (rc)
{
// We have to handle a format space error as a special case of a FID
// mismatch. We should only get the space error if columns have been added
// to the DB2 table without MySQL's knowledge, which is effectively a
// FID problem.
if (rc == QMY_ERR_RTNFMT)
{
rc = QMY_ERR_LVLID_MISMATCH;
getErrTxt(rc);
}
return rc;
}
convFromEbcdic(((format_hdr_t*)formatSpace)->FilLvlId, fileLevelID, sizeof(fileLevelID));
......@@ -274,7 +288,7 @@ db2i_table::~db2i_table()
if (logicalFiles)
{
for (int k = 0; k < mysqlTable->keys; ++k)
for (int k = 0; k < logicalFileCount; ++k)
{
delete logicalFiles[k];
}
......@@ -302,11 +316,40 @@ void db2i_table::getDB2QualifiedNameFromPath(const char* path, char* to)
}
size_t db2i_table::smartFilenameToTableName(const char *in, char* out, size_t outlen)
{
if (strchr(in, '@') == NULL)
{
return filename_to_tablename(in, out, outlen);
}
char* test = (char*) my_malloc(outlen, MYF(MY_WME));
filename_to_tablename(in, test, outlen);
char* cur = test;
while (*cur)
{
if ((*cur <= 0x20) || (*cur >= 0x80))
{
strncpy(out, in, outlen);
my_free(test, MYF(0));
return min(outlen, strlen(out));
}
++cur;
}
strncpy(out, test, outlen);
my_free(test, MYF(0));
return min(outlen, strlen(out));
}
void db2i_table::filenameToTablename(const char* in, char* out, size_t outlen)
{
if (strchr(in, '#') == NULL)
{
filename_to_tablename(in, out, outlen);
smartFilenameToTableName(in, out, outlen);
return;
}
......@@ -326,7 +369,7 @@ void db2i_table::filenameToTablename(const char* in, char* out, size_t outlen)
memcpy(temp, part1, min(outlen, part2 - part1));
temp[min(outlen-1, part2-part1)] = 0;
int32 accumLen = filename_to_tablename(temp, out, outlen);
int32 accumLen = smartFilenameToTableName(temp, out, outlen);
if (part2 && (accumLen + 4 < outlen))
{
......@@ -337,7 +380,7 @@ void db2i_table::filenameToTablename(const char* in, char* out, size_t outlen)
memcpy(temp, part3, min(outlen, part4-part3));
temp[min(outlen-1, part4-part3)] = 0;
accumLen += filename_to_tablename(temp, strend(out), outlen-accumLen);
accumLen += smartFilenameToTableName(temp, strend(out), outlen-accumLen);
if (part4 && (accumLen + (strend(in) - part4 + 1) < outlen))
{
......
......@@ -270,6 +270,7 @@ class db2i_table
void findConversionDefinition(enum_conversionDirection direction, uint16 fieldID);
static void filenameToTablename(const char* in, char* out, size_t outlen);
static size_t smartFilenameToTableName(const char *in, char* out, size_t outlen);
void convertNativeToSQLName(const char* input,
char* output)
{
......@@ -301,6 +302,7 @@ class db2i_table
iconv_t* conversionDefinitions[2];
const TABLE_SHARE* mysqlTable;
uint16 logicalFileCount;
char* db2LibNameEbcdic; // Quoted and in EBCDIC
char* db2LibNameAscii;
char* db2TableNameEbcdic;
......@@ -326,22 +328,18 @@ class db2i_table
*/
class db2i_file
{
enum RowFormats
{
readOnly = 0,
readWrite,
maxRowFormats
};
public:
mutable struct RowFormat
struct RowFormat
{
uint16 readRowLen;
uint16 readRowNullOffset;
uint16 writeRowLen;
uint16 writeRowNullOffset;
char inited;
} formats[maxRowFormats];
};
public:
// Construct an instance for a physical file.
db2i_file(db2i_table* table);
......@@ -375,31 +373,29 @@ class db2i_file
// This obtains the row layout associated with a particular access intent for
// an open instance of the file.
int useFile(FILE_HANDLE instanceHandle,
char intent,
char commitLevel,
const RowFormat** activeFormat) const
int obtainRowFormat(FILE_HANDLE instanceHandle,
char intent,
char commitLevel,
const RowFormat** activeFormat) const
{
DBUG_ENTER("db2i_file::useFile");
DBUG_ENTER("db2i_file::obtainRowFormat");
RowFormat* rowFormat;
if (intent == QMY_UPDATABLE)
rowFormat = &(formats[readWrite]);
else if (intent == QMY_READ_ONLY)
rowFormat = &(formats[readOnly]);
else
DBUG_ASSERT(0);
if (!rowFormat->inited)
if (unlikely(!rowFormat->inited))
{
int rc;
rc = db2i_ileBridge::getBridgeForThread()->initFileForIO(instanceHandle,
intent,
commitLevel,
&(rowFormat->writeRowLen),
&(rowFormat->writeRowNullOffset),
&(rowFormat->readRowLen),
&(rowFormat->readRowNullOffset));
int rc = db2i_ileBridge::getBridgeForThread()->
initFileForIO(instanceHandle,
intent,
commitLevel,
&(rowFormat->writeRowLen),
&(rowFormat->writeRowNullOffset),
&(rowFormat->readRowLen),
&(rowFormat->readRowNullOffset));
if (rc) DBUG_RETURN(rc);
rowFormat->inited = 1;
}
......@@ -426,6 +422,15 @@ class db2i_file
}
private:
enum RowFormats
{
readOnly = 0,
readWrite,
maxRowFormats
};
mutable RowFormat formats[maxRowFormats];
void commonCtorInit();
char* db2FileName; // Quoted and in EBCDIC
......
......@@ -894,6 +894,7 @@ int32 db2i_ileBridge::savepoint(uint8 function,
return rc;
}
static ILEMemHandle traceSpcHandle;
/**
Do initialization for the QMY_* APIs.
......@@ -902,7 +903,8 @@ int32 db2i_ileBridge::savepoint(uint8 function,
@return 0 if successful; error otherwise
*/
int32 db2i_ileBridge::initILE(const char* aspName)
int32 db2i_ileBridge::initILE(const char* aspName,
uint16* traceCtlPtr)
{
// We forego the typical thread-based parms space because MySQL doesn't
// allow us to clean it up before checking for memory leaks. As a result
......@@ -916,6 +918,8 @@ int32 db2i_ileBridge::initILE(const char* aspName)
return rc;
}
registerPtr(traceCtlPtr, &traceSpcHandle);
struct ParmBlock
{
Qmy_MINI0100 parms;
......@@ -935,6 +939,9 @@ int32 db2i_ileBridge::initILE(const char* aspName)
memset(paddedName, ' ', sizeof(paddedName));
memcpy(paddedName, aspName, strlen(aspName));
convToEbcdic(paddedName, parmBlock->parms.RDBName, strlen(paddedName));
parmBlock->parms.RDBNamLen = strlen(paddedName);
parmBlock->parms.TrcSpcHnd = traceSpcHandle;
rc = doIt();
......@@ -963,6 +970,8 @@ int32 db2i_ileBridge::exitILE()
{
reportSystemAPIError(rc, (Qmy_Error_output_t*)parmBlock->outParms);
}
unregisterPtr(traceSpcHandle);
DBUG_PRINT("db2i_ileBridge::exitILE", ("Registered ptrs remaining: %d", registeredPtrs));
#ifndef DBUG_OFF
......@@ -1267,7 +1276,7 @@ int32 db2i_ileBridge::quiesceFileInstance(FILE_HANDLE rfileHandle)
return rc;
}
void db2i_ileBridge::PreservedHandleList::add(const char* newname, FILE_HANDLE newhandle)
void db2i_ileBridge::PreservedHandleList::add(const char* newname, FILE_HANDLE newhandle, IBMDB2I_SHARE* share)
{
NameHandlePair *newPair = (NameHandlePair*)my_malloc(sizeof(NameHandlePair), MYF(MY_WME));
......@@ -1276,11 +1285,12 @@ void db2i_ileBridge::PreservedHandleList::add(const char* newname, FILE_HANDLE n
strcpy(newPair->name, newname);
newPair->handle = newhandle;
newPair->share = share;
DBUG_PRINT("db2i_ileBridge", ("Added handle %d for %s", uint32(newhandle), newname));
}
FILE_HANDLE db2i_ileBridge::PreservedHandleList::findAndRemove(const char* fileName)
FILE_HANDLE db2i_ileBridge::PreservedHandleList::findAndRemove(const char* fileName, IBMDB2I_SHARE** share)
{
NameHandlePair* current = head;
NameHandlePair* prev = NULL;
......@@ -1291,6 +1301,7 @@ FILE_HANDLE db2i_ileBridge::PreservedHandleList::findAndRemove(const char* fileN
if (strcmp(fileName, current->name) == 0)
{
FILE_HANDLE tmp = current->handle;
*share = current->share;
if (prev)
prev->next = next;
if (current == head)
......
......@@ -62,6 +62,7 @@ enum db2i_InfoRequestSpec
};
extern handlerton *ibmdb2i_hton;
struct IBMDB2I_SHARE;
const uint32 db2i_ileBridge_MAX_INPARM_SIZE = 512;
const uint32 db2i_ileBridge_MAX_OUTPARM_SIZE = 512;
......@@ -220,7 +221,8 @@ class db2i_ileBridge
uint32* outLen,
uint32* outCnt);
int32 optimizeTable(FILE_HANDLE rfileHandle);
static int32 initILE(const char* aspName);
static int32 initILE(const char* aspName,
uint16* traceCtlPtr);
int32 initFileForIO(FILE_HANDLE rfileHandle,
char accessIntent,
char commitLevel,
......@@ -336,9 +338,9 @@ class db2i_ileBridge
@param newhandle The handle associated with newname
*/
void preserveHandle(const char* newname, FILE_HANDLE newhandle)
void preserveHandle(const char* newname, FILE_HANDLE newhandle, IBMDB2I_SHARE* share)
{
pendingLockedHandles.add(newname, newhandle);
pendingLockedHandles.add(newname, newhandle, share);
}
/**
......@@ -348,9 +350,10 @@ class db2i_ileBridge
@return The handle associated with name
*/
FILE_HANDLE findAndRemovePreservedHandle(const char* name)
FILE_HANDLE findAndRemovePreservedHandle(const char* name, IBMDB2I_SHARE** share)
{
return pendingLockedHandles.findAndRemove(name);
FILE_HANDLE hdl = pendingLockedHandles.findAndRemove(name, share);
return hdl;
}
/**
......@@ -380,7 +383,7 @@ class db2i_ileBridge
@return A pointer to the 7 character message ID.
*/
const char* getErrorMsgID()
static const char* getErrorMsgID()
{
return ((Qmy_Error_output_t*)parms()->outParms)->MsgId;
}
......@@ -413,6 +416,13 @@ class db2i_ileBridge
return HA_ERR_NO_SUCH_TABLE;
case QMY_ERR_NON_UNIQUE_KEY:
return ER_DUP_ENTRY;
case QMY_ERR_MSGID:
{
if (memcmp(getErrorMsgID(), DB2I_CPF503A, 7) == 0)
return HA_ERR_ROW_IS_REFERENCED;
if (memcmp(getErrorMsgID(), DB2I_SQL0538, 7) == 0)
return HA_ERR_CANNOT_ADD_FOREIGN;
}
}
return rc;
}
......@@ -458,14 +468,15 @@ class db2i_ileBridge
{
friend db2i_ileBridge* db2i_ileBridge::createNewBridge(CONNECTION_HANDLE);
public:
void add(const char* newname, FILE_HANDLE newhandle);
FILE_HANDLE findAndRemove(const char* fileName);
void add(const char* newname, FILE_HANDLE newhandle, IBMDB2I_SHARE* share);
FILE_HANDLE findAndRemove(const char* fileName, IBMDB2I_SHARE** share);
private:
struct NameHandlePair
{
char name[FN_REFLEN];
FILE_HANDLE handle;
IBMDB2I_SHARE* share;
NameHandlePair* next;
}* head;
} pendingLockedHandles;
......
......@@ -257,7 +257,7 @@ void IOAsyncReadBuffer::newReadRequest(FILE_HANDLE infile,
int fildes[2];
int ileDescriptor = QMY_REUSE;
closePipe();
interruptRead();
if (likely(useAsync))
{
......
......@@ -73,10 +73,12 @@ class IORowBuffer
Sets up the buffer to hold the size indicated.
@param rowLen length of the rows that will be stored in this buffer
@param nullMapOffset position of null map within each row
@param size buffer size requested
*/
void allocBuf(uint32 rowLen, uint32 size)
void allocBuf(uint32 rowLen, uint16 nullMapOffset, uint32 size)
{
nullOffset = nullMapOffset;
uint32 newSize = size + sizeof(BufferHdr_t);
// If the internal structure of the row is changing, we need to
// remember this and notify the subclasses via initAfterAllocate();
......@@ -129,7 +131,9 @@ class IORowBuffer
};
uint32 getRowCapacity() const {return rowCapacity;}
uint32 getRowNullOffset() const {return nullOffset;}
uint32 getRowLength() const {return rowLength;}
protected:
/**
Called prior to freeing buffer storage so that subclasses can do
......@@ -150,6 +154,7 @@ class IORowBuffer
uint32 allocSize;
uint32 rowCapacity;
uint32 rowLength;
uint16 nullOffset;
uint32& usedRows() const { return ((BufferHdr_t*)(char*)data)->UsedRowCnt; }
uint32& maxRows() const {return ((BufferHdr_t*)(char*)data)->MaxRowCnt; }
};
......@@ -207,7 +212,7 @@ class IOReadBuffer : public IORowBuffer
IOReadBuffer() {;}
IOReadBuffer(uint32 rows, uint32 rowLength)
{
allocBuf(rows, rows * rowLength);
allocBuf(rows, 0, rows * rowLength);
maxRows() = rows;
}
......
......@@ -92,4 +92,16 @@ bool convertMySQLNameToDB2Name(const char* input,
return (o <= outlen-1);
}
bool isUpperOrQuote(const CHARSET_INFO* cs, const char* s)
{
while (*s)
{
if (my_isupper(cs, *s) || (*s == '"'))
++s;
else
return false;
}
return true;
}
#endif
......@@ -140,6 +140,17 @@ ha_rows ha_ibmdb2i::records_in_range(uint inx,
}
keyCnt = maxKeyCnt >= minKeyCnt ? maxKeyCnt : minKeyCnt;
/*
Handle the special case where MySQL does not pass either a min or max
key range. In this case, set the key count to 1 (knowing that there
is at least one key field) to flow through and create one bounds structure.
When both the min and max key ranges are nil, the bounds structure will
specify positive and negative infinity and DB2 will estimate the total
number of rows. */
if (keyCnt == 0)
keyCnt = 1;
/*
Allocate the space needed to pass range information to DB2. The
space must be large enough to store the following:
......@@ -196,8 +207,7 @@ ha_rows ha_ibmdb2i::records_in_range(uint inx,
estimate. If one bound is null, both bounds must be null. When the bound
is not null, the data offset and length must be set, and the literal
value stored for access by DB2.
*/
*/
for (int partsInUse = 0; partsInUse < keyCnt; ++partsInUse)
{
Field *field= curKey.key_part[partsInUse].field;
......@@ -298,19 +308,28 @@ ha_rows ha_ibmdb2i::records_in_range(uint inx,
else
tempLen = field->field_length;
if (litDefPtr->DataType == QMY_CHAR || litDefPtr->DataType == QMY_VARCHAR ||
(strncmp(fieldCharSet->csname, "utf8", sizeof("utf8")) == 0))
{
/* Determine if we are dealing with a partial key and if so, find the end of the partial key. */
if (litDefPtr->DataType == QMY_CHAR || litDefPtr->DataType == QMY_VARCHAR )
{ /* Char or varchar. If UTF8, no conversion is done to DB2 graphic.) */
endOfMinPtr = (char*)memchr(tempMinPtr,field->charset()->min_sort_char,tempLen);
if (endOfMinPtr)
endOfLiteralPtr = tempPtr + (((uint32_t)(endOfMinPtr - tempMinPtr)) *
(litDefPtr->DataType == QMY_CHAR || litDefPtr->DataType == QMY_VARCHAR ? 1 : 2));
endOfLiteralPtr = tempPtr + ((uint32_t)(endOfMinPtr - tempMinPtr));
}
else
{
endOfMinPtr = (char*)wmemchr((wchar_t*)tempMinPtr,field->charset()->min_sort_char,tempLen/2);
if (endOfMinPtr)
endOfLiteralPtr = tempPtr + (endOfMinPtr - tempMinPtr);
if (strncmp(fieldCharSet->csname, "utf8", sizeof("utf8")) == 0)
{ /* The MySQL charset is UTF8 but we are converting to graphic on DB2. Divide number of UTF8 bytes
by 3 to get the number of characters, then multiple by 2 for double-byte graphic.*/
endOfMinPtr = (char*)memchr(tempMinPtr,field->charset()->min_sort_char,tempLen);
if (endOfMinPtr)
endOfLiteralPtr = tempPtr + (((uint32_t)((endOfMinPtr - tempMinPtr)) / 3) * 2);
}
else
{ /* The DB2 data type is graphic or vargraphic, and we are not converting from UTF8 to graphic. */
endOfMinPtr = (char*)wmemchr((wchar_t*)tempMinPtr,field->charset()->min_sort_char,tempLen/2);
if (endOfMinPtr)
endOfLiteralPtr = tempPtr + (endOfMinPtr - tempMinPtr);
}
}
/* Enforce here that a partial is only allowed on the last field position
of the key composite */
......@@ -354,6 +373,11 @@ ha_rows ha_ibmdb2i::records_in_range(uint inx,
}
else // max_key field is not null
{
if (boundsPtr->LoBound.IsNull[0] == QMY_YES) // select where x < 10 or x is null
{
rc = HA_POS_ERROR;
break;
}
if (!reuseLiteral)
{
if (literalCnt)
......@@ -381,7 +405,7 @@ ha_rows ha_ibmdb2i::records_in_range(uint inx,
litDefPtr->DataType == QMY_GRAPHIC || litDefPtr->DataType == QMY_VARGRAPHIC))
{
if (litDefPtr->DataType == QMY_VARCHAR || litDefPtr->DataType == QMY_VARGRAPHIC)
{
{
tempPtr = literalPtr + sizeof(uint16);
}
else
......
This diff is collapsed.
......@@ -65,7 +65,7 @@ OF SUCH DAMAGE.
It is used to describe the underlying table definition, and it caches
table statistics.
*/
typedef struct st_ibmdb2i_share {
struct IBMDB2I_SHARE {
char *table_name;
uint table_name_length,use_count;
pthread_mutex_t mutex;
......@@ -110,7 +110,7 @@ typedef struct st_ibmdb2i_share {
ulong data_file_length;
} cachedStats;
} IBMDB2I_SHARE;
};
class ha_ibmdb2i: public handler
{
......@@ -143,16 +143,15 @@ class ha_ibmdb2i: public handler
// Array of file handles belonging to the underlying LFs
FILE_HANDLE* indexHandles;
// Pointer to a definition of the layout of the row buffer for the file
// described by activeHandle
const db2i_file::RowFormat* activeFormat;
// Flag to indicate whether a call needs to be made to unlock a row when
// a read operation has ended. DB2 will handle row unlocking as we move
// through rows, but if an operation ends before we reach the end of a file,
// DB2 needs to know to unlock the last row read.
bool releaseRowNeeded;
// Pointer to a definition of the layout of the row buffer for the file
// described by activeHandle
const db2i_file::RowFormat* activeFormat;
IORowBuffer keyBuf;
uint32 keyLen;
......@@ -190,6 +189,7 @@ class ha_ibmdb2i: public handler
// The access intent indicated by the last external_locks() call.
// May be either QMY_READ or QMY_UPDATABLE
char accessIntent;
char readAccessIntent;
ha_rows* indexReadSizeEstimates;
......@@ -361,6 +361,20 @@ class ha_ibmdb2i: public handler
AS_VARCHAR
};
enum enum_ZeroDate
{
NO_SUBSTITUTE,
SUBSTITUTE_0001_01_01
};
enum enum_YearFormat
{
CHAR4,
SMALLINT
};
enum_ZeroDate cachedZeroDateOption;
IBMDB2I_SHARE *get_share(const char *table_name, TABLE *table);
int free_share(IBMDB2I_SHARE *share);
int32 mungeDB2row(uchar* record, const char* dataPtr, const char* nullMapPtr, bool skipLOBs);
......@@ -396,10 +410,9 @@ class ha_ibmdb2i: public handler
}
int useDataFile(char intent)
int useDataFile()
{
DBUG_ENTER("ha_ibmdb2i::useDataFile");
DBUG_PRINT("ha_ibmdb2i::useDataFile", ("Intent: %d", intent));
int rc = 0;
if (!dataHandle)
......@@ -408,20 +421,11 @@ class ha_ibmdb2i: public handler
DBUG_RETURN(0);
DBUG_ASSERT(activeHandle == 0);
if (likely(rc == 0))
{
rc = db2Table->dataFile()->useFile(dataHandle,
intent,
getCommitLevel(),
&activeFormat);
if (likely(rc == 0))
{
activeHandle = dataHandle;
bumpInUseCounter(1);
}
activeHandle = dataHandle;
bumpInUseCounter(1);
}
DBUG_RETURN(rc);
......@@ -448,7 +452,7 @@ class ha_ibmdb2i: public handler
DBUG_VOID_RETURN;
}
int useIndexFile(char intent, int idx);
int useIndexFile(int idx);
void releaseIndexFile(int idx)
{
......@@ -526,7 +530,10 @@ class ha_ibmdb2i: public handler
int getFieldTypeMapping(Field* field,
String& mapping,
enum_TimeFormat timeFormate,
enum_BlobMapping blobMapping);
enum_BlobMapping blobMapping,
enum_ZeroDate zeroDateHandling,
bool propagateDefaults,
enum_YearFormat yearFormat);
int getKeyFromName(const char* name, size_t len);
......@@ -564,6 +571,9 @@ class ha_ibmdb2i: public handler
{
DBUG_ASSERT(activeReadBuf->rowCount() == 1);
row = activeReadBuf->readNextRow(orientation, currentRRN);
if (unlikely(!row))
rc = activeReadBuf->lastrc();
}
}
}
......@@ -571,7 +581,7 @@ class ha_ibmdb2i: public handler
if (likely(rc == 0))
{
rrnAssocHandle = activeHandle;
rc = mungeDB2row(destination, row, row+activeFormat->readRowNullOffset, false);
rc = mungeDB2row(destination, row, row+activeReadBuf->getRowNullOffset(), false);
}
return rc;
}
......@@ -631,7 +641,7 @@ class ha_ibmdb2i: public handler
}
}
int rc = file->useFile(handle, intent, getCommitLevel(), &activeFormat);
int rc = file->obtainRowFormat(handle, intent, getCommitLevel(), &activeFormat);
if (likely(rc == 0))
{
activeHandle = handle;
......@@ -641,12 +651,25 @@ class ha_ibmdb2i: public handler
DBUG_RETURN(rc);
}
int prepReadBuffer(ha_rows rowsToRead);
void prepWriteBuffer(ha_rows rowsToWrite);
const db2i_file* getFileForActiveHandle() const
{
if (activeHandle == dataHandle)
return db2Table->dataFile();
else
for (uint i = 0; i < table_share->keys; ++i)
if (indexHandles[i] == activeHandle)
return db2Table->indexFile(i);
DBUG_ASSERT(0);
return NULL;
}
int prepReadBuffer(ha_rows rowsToRead, const db2i_file* file, char intent);
int prepWriteBuffer(ha_rows rowsToWrite, const db2i_file* file);
void invalidateCachedStats()
{
share->cachedStats.invalidate(rowCount | deletedRowCount | objLength | meanRowLen | ioCount);
share->cachedStats.invalidate(rowCount | deletedRowCount | objLength |
meanRowLen | ioCount);
}
void warnIfInvalidData()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment