Skip to content

Commit

Permalink
fix: Alter table issue (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
abmusse authored Oct 4, 2022
1 parent 7339d24 commit 7f96f1a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 47 deletions.
4 changes: 2 additions & 2 deletions db2i_blobCollection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ BlobCollection::getSizeToAllocate(int fieldIndex, bool& shouldProtect)

uint curMaxSize = table->getBlobFieldActualSize(fieldIndex);

uint defaultAllocSize = min(defaultAllocation, fieldLength);
uint defaultAllocSize = std::min(defaultAllocation, fieldLength);

return max(defaultAllocSize, curMaxSize);
return std::max(defaultAllocSize, curMaxSize);

}

Expand Down
34 changes: 17 additions & 17 deletions db2i_conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,13 @@ int ha_ibmdb2i::getFieldTypeMapping(Field* field,
{
if (field->type() == MYSQL_TYPE_STRING)
{
sprintf(stringBuildBuffer, "BINARY(%d)", max(fieldLength, 1));
sprintf(stringBuildBuffer, "BINARY(%u)", std::max(fieldLength, 1u));
}
else
{
if (fieldLength <= MAX_VARCHAR_LENGTH)
{
sprintf(stringBuildBuffer, "VARBINARY(%d)", max(fieldLength, 1));
sprintf(stringBuildBuffer, "VARBINARY(%u)", std::max(fieldLength, 1u));
}
else if (blobMapping == AS_VARCHAR &&
(field->flags & PART_KEY_FLAG))
Expand All @@ -550,8 +550,8 @@ int ha_ibmdb2i::getFieldTypeMapping(Field* field,
}
else
{
fieldLength = min(MAX_BLOB_LENGTH, fieldLength);
sprintf(stringBuildBuffer, "BLOB(%d)", max(fieldLength, 1));
fieldLength = std::min(MAX_BLOB_LENGTH, fieldLength);
sprintf(stringBuildBuffer, "BLOB(%u)", std::max(fieldLength, 1u));
}
}
mapping.append(stringBuildBuffer);
Expand Down Expand Up @@ -586,14 +586,14 @@ int ha_ibmdb2i::getFieldTypeMapping(Field* field,
return 1;
if (fieldCharSet->mbmaxlen > 1 && (!is_utf8 || is_utf8_general_ci))
{
sprintf(stringBuildBuffer, "GRAPHIC(%d)", max(fieldLength / fieldCharSet->mbmaxlen, 1)); // Number of characters
sprintf(stringBuildBuffer, "GRAPHIC(%u)", std::max(fieldLength / fieldCharSet->mbmaxlen, 1u)); // Number of characters
// Need to set CCSID to 1200 (UTF-16) when using multi-byte charsets
// As well as when the collation is utf*_general_ci because of sort sequence issues
db2Ccsid = 1200;
}
else
{
sprintf(stringBuildBuffer, "CHAR(%d)", max(fieldLength, 1));
sprintf(stringBuildBuffer, "CHAR(%u)", std::max(fieldLength, 1u));
}
mapping.append(stringBuildBuffer);
}
Expand All @@ -603,14 +603,14 @@ int ha_ibmdb2i::getFieldTypeMapping(Field* field,
{
if (fieldCharSet->mbmaxlen > 1 && (!is_utf8 || is_utf8_general_ci))
{
sprintf(stringBuildBuffer, "VARGRAPHIC(%d)", max(fieldLength / fieldCharSet->mbmaxlen, 1)); // Number of characters
sprintf(stringBuildBuffer, "VARGRAPHIC(%u)", std::max(fieldLength / fieldCharSet->mbmaxlen, 1u)); // Number of characters
// Need to set CCSID to 1200 (UTF-16) when using multi-byte charsets
// As well as when the collation is utf*_general_ci because of sort sequence issues
db2Ccsid = 1200;
}
else
{
sprintf(stringBuildBuffer, "VARCHAR(%d)", max(fieldLength, 1));
sprintf(stringBuildBuffer, "VARCHAR(%u)", std::max(fieldLength, 1u));
}
}
else if (blobMapping == AS_VARCHAR &&
Expand All @@ -630,18 +630,18 @@ int ha_ibmdb2i::getFieldTypeMapping(Field* field,
}
else
{
fieldLength = min(MAX_BLOB_LENGTH, fieldLength);
fieldLength = std::min(MAX_BLOB_LENGTH, fieldLength);

if (fieldCharSet->mbmaxlen > 1 && (!is_utf8 || is_utf8_general_ci))
{
sprintf(stringBuildBuffer, "DBCLOB(%d)", max(fieldLength / fieldCharSet->mbmaxlen, 1)); // Number of characters
sprintf(stringBuildBuffer, "DBCLOB(%u)", std::max(fieldLength / fieldCharSet->mbmaxlen,1u)); // Number of characters
// Need to set CCSID to 1200 (UTF-16) when using multi-byte charsets
// As well as when the collation is utf*_general_ci because of sort sequence issues
db2Ccsid = 1200;
}
else
{
sprintf(stringBuildBuffer, "CLOB(%d)", max(fieldLength, 1)); // Number of characters
sprintf(stringBuildBuffer, "CLOB(%u)", std::max(fieldLength, 1u)); // Number of characters
}
}

Expand Down Expand Up @@ -689,7 +689,7 @@ int32 ha_ibmdb2i::convertMySQLtoDB2(Field* field, const DB2Field& db2Field, char
{
uint precision= ((Field_new_decimal*)field)->precision;
uint scale= field->decimals();
uint db2Precision = min(precision, MAX_DEC_PRECISION);
uint db2Precision = std::min(precision, MAX_DEC_PRECISION);
uint truncationAmount = precision - db2Precision;

if (scale >= truncationAmount)
Expand Down Expand Up @@ -1160,8 +1160,8 @@ int32 ha_ibmdb2i::convertMySQLtoDB2(Field* field, const DB2Field& db2Field, char
if (maxDisplayLength == 0 && db2FieldType == QMY_GRAPHIC)
maxDb2BytesToStore = 2;
else
maxDb2BytesToStore = min(((bytesToStore * 2) / fieldCharSet->mbminlen),
((maxDisplayLength * 2) / fieldCharSet->mbmaxlen));
maxDb2BytesToStore = std::min(bytesToStore * 2 / fieldCharSet->mbminlen,
maxDisplayLength * 2 / fieldCharSet->mbmaxlen);

if (bytesToStore == 0)
db2BytesToStore = 0;
Expand Down Expand Up @@ -1205,8 +1205,8 @@ int32 ha_ibmdb2i::convertMySQLtoDB2(Field* field, const DB2Field& db2Field, char
else // Else Far East, special UTF8 or non-special UTF8/UCS2
{
size_t maxDb2BytesToStore;
maxDb2BytesToStore = min(((bytesToStore * 2) / fieldCharSet->mbminlen),
((maxDisplayLength * 2) / fieldCharSet->mbmaxlen));
maxDb2BytesToStore = std::min(bytesToStore * 2 / fieldCharSet->mbminlen,
maxDisplayLength * 2 / fieldCharSet->mbmaxlen);
temp = getCharacterConversionBuffer(field->field_index, maxDb2BytesToStore);
rc = convertFieldChars(toDB2, field->field_index, (char*)dataToStore,temp,bytesToStore, maxDb2BytesToStore, &db2BytesToStore);
if (rc)
Expand Down Expand Up @@ -1258,7 +1258,7 @@ int32 ha_ibmdb2i::convertDB2toMySQL(const DB2Field& db2Field, Field* field, cons
{
uint precision= ((Field_new_decimal*)field)->precision;
uint scale= field->decimals();
uint db2Precision = min(precision, MAX_DEC_PRECISION);
uint db2Precision = std::min(precision, MAX_DEC_PRECISION);
uint decimalPlace = precision-scale+1;
char temp[80];

Expand Down
25 changes: 15 additions & 10 deletions db2i_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ size_t db2i_table::smartFilenameToTableName(const char *in, char* out, size_t ou
{
strncpy(out, in, outlen);
my_free(test);
return min(outlen, strlen(out));
return std::min(outlen, strlen(out));
}
++cur;
}

strncpy(out, test, outlen);
my_free(test);
return min(outlen, strlen(out));
return std::min(outlen, strlen(out));
}

void db2i_table::filenameToTablename(const char* in, char* out, size_t outlen)
Expand All @@ -376,20 +376,25 @@ void db2i_table::filenameToTablename(const char* in, char* out, size_t outlen)
if (!part4)
part4 = strend(in);
}

memcpy(temp, part1, min(outlen, part2 - part1));
temp[min(outlen-1, part2-part1)] = 0;


{
size_t num_bytes = std::min(outlen-1, static_cast<size_t>(part2 - part1));
memcpy(temp, part1, num_bytes);
temp[num_bytes] = 0;
}

int32 accumLen = smartFilenameToTableName(temp, out, outlen);

if (part2 && (accumLen + 4 < (int) outlen))
{
strcat(out, "#P#");
accumLen += 4;

memset(temp, 0, min(outlen, part2-part1));
memcpy(temp, part3, min(outlen, part4-part3));
temp[min(outlen-1, part4-part3)] = 0;
{
size_t num_bytes = std::min(outlen, static_cast<size_t>(part4-part3));
memcpy(temp, part3, std::min(outlen, num_bytes));
temp[std::min(static_cast<size_t>(outlen-1), num_bytes)] = 0;
}

accumLen += smartFilenameToTableName(temp, strend(out), outlen-accumLen);

Expand Down Expand Up @@ -496,7 +501,7 @@ int32 db2i_table::appendQualifiedIndexFileName(const char* indexName,

strncat(generatedName,
tableName+1,
min(strlen(tableName), (MAX_DB2_FILENAME_LENGTH-lenWithoutFile))-2 );
std::min(strlen(tableName), static_cast<size_t>(MAX_DB2_FILENAME_LENGTH-lenWithoutFile))-2 );

char finalName[MAX_DB2_FILENAME_LENGTH+1];
convertMySQLNameToDB2Name(generatedName, finalName, sizeof(finalName), true, (format==ASCII_SQL));
Expand Down
3 changes: 1 addition & 2 deletions db2i_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ OF SUCH DAMAGE.
* Explicit macro will be used.
*/

#define min(a,b) ((long long)(a)>(long long)(b) ? (b) : (a))
#define max(a,b) ((long long)(a)<(long long)(b) ? (b) : (a))
#include <algorithm>

#define db2i_beint16_from_ptr2leint16(V,M) \
do { int16 def_temp;\
Expand Down
2 changes: 1 addition & 1 deletion db2i_ileBridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ int32 db2i_ileBridge::prepOpen(const char* statement,
{
Qmy_MSPO0100_output* output = (Qmy_MSPO0100_output*)parmBlock->outParms;
*rfileHandle = output->ObjHnd;
*recLength = max(output->InNxtRowOff, output->OutNxtRowOff);
*recLength = std::max(output->InNxtRowOff, output->OutNxtRowOff);
}


Expand Down
4 changes: 2 additions & 2 deletions db2i_misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ EXTERN bool convertMySQLNameToDB2Name(const char* input,
bool delimit,
bool delimitQuotes)
{
uint o = 0;
size_t o = 0;
if (delimit)
output[o++] = '"';

Expand All @@ -100,7 +100,7 @@ EXTERN bool convertMySQLNameToDB2Name(const char* input,

if (delimit)
output[o++] = '"';
output[min(o, outlen-1)] = 0; // This isn't the most user-friendly way to handle overflows,
output[std::min(o, outlen-1)] = 0; // This isn't the most user-friendly way to handle overflows,
// but at least its safe.
return (o <= outlen-1);
}
Expand Down
2 changes: 1 addition & 1 deletion db2i_safeString.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ OF SUCH DAMAGE.

SafeString& SafeString::strncat(const char* str, size_t len)
{
uint64 amountToCopy = min((allocSize-1) - curPos, len);
size_t amountToCopy = std::min(allocSize-1 - curPos, len);
memcpy(buf + curPos, str, amountToCopy);
curPos += amountToCopy;
buf[curPos] = 0;
Expand Down
2 changes: 1 addition & 1 deletion db2i_safeString.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SafeString

private:
char* buf;
uint64 curPos;
size_t curPos;
size_t allocSize;
};

Expand Down
21 changes: 10 additions & 11 deletions ha_ibmdb2i.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static const char __NOT_NULL_VALUE_EBCDIC = 0xF0; // '0'
static const char __NULL_VALUE_EBCDIC = 0xF1; // '1'
static const char __DEFAULT_VALUE_EBCDIC = 0xC4; // 'D'
static const char BlankASPName[19] = " ";
static const int DEFAULT_MAX_ROWS_TO_BUFFER = 4096;
static const ha_rows DEFAULT_MAX_ROWS_TO_BUFFER = 4096;

static const char SAVEPOINT_PREFIX[] = {0xD4, 0xE8, 0xE2, 0xD7}; // MYSP (in EBCDIC)

Expand Down Expand Up @@ -2791,10 +2791,9 @@ int ha_ibmdb2i::prepReadBuffer(ha_rows rowsToRead, const db2i_file* file, char i
forceSingleRowRead = true;
rowsToRead = 1;
}
rowsToRead = std::min(stats.records+1,std::min(rowsToRead, DEFAULT_MAX_ROWS_TO_BUFFER));

rowsToRead = min(stats.records+1,min(rowsToRead, DEFAULT_MAX_ROWS_TO_BUFFER));

uint bufSize = min((format->readRowLen * rowsToRead), THDVAR(thd, max_read_buffer_size));
uint bufSize = std::min(format->readRowLen * rowsToRead, static_cast<ha_rows>(THDVAR(thd, max_read_buffer_size)));
multiRowReadBuf.allocBuf(format->readRowLen, format->readRowNullOffset, bufSize);
activeReadBuf = &multiRowReadBuf;

Expand Down Expand Up @@ -2830,9 +2829,9 @@ int ha_ibmdb2i::prepWriteBuffer(ha_rows rowsToWrite, const db2i_file* file)

if (unlikely(rc)) DBUG_RETURN(rc);

rowsToWrite = min(rowsToWrite, DEFAULT_MAX_ROWS_TO_BUFFER);
rowsToWrite = std::min(rowsToWrite, DEFAULT_MAX_ROWS_TO_BUFFER);

uint bufSize = min((format->writeRowLen * rowsToWrite), THDVAR(ha_thd(), max_write_buffer_size));
uint bufSize = std::min((format->writeRowLen * rowsToWrite), static_cast<ha_rows>(THDVAR(ha_thd(), max_write_buffer_size)));
multiRowWriteBuf.allocBuf(format->writeRowLen, format->writeRowNullOffset, bufSize);
activeWriteBuf = &multiRowWriteBuf;

Expand Down Expand Up @@ -2916,8 +2915,8 @@ int ha_ibmdb2i::flushWrite(FILE_HANDLE fileHandle, uchar* buf )
else
{
char unknownIndex[MAX_DB2_FILENAME_LENGTH+1];
convFromEbcdic(lastDupKeyNamePtr, unknownIndex, min(lastDupKeyNameLen, MAX_DB2_FILENAME_LENGTH));
unknownIndex[min(lastDupKeyNameLen, MAX_DB2_FILENAME_LENGTH)] = 0;
convFromEbcdic(lastDupKeyNamePtr, unknownIndex, std::min(lastDupKeyNameLen, static_cast<uint32>(MAX_DB2_FILENAME_LENGTH)));
unknownIndex[std::min(lastDupKeyNameLen, static_cast<uint32>(MAX_DB2_FILENAME_LENGTH))] = 0;
getErrTxt(DB2I_ERR_UNKNOWN_IDX, unknownIndex);
}
}
Expand Down Expand Up @@ -3292,7 +3291,7 @@ void ha_ibmdb2i::doInitialRead(char orientation,
if (forceSingleRowRead)
rowsToBuffer = 1;
else
rowsToBuffer = min(rowsToBuffer, activeReadBuf->getRowCapacity());
rowsToBuffer = std::min(rowsToBuffer, activeReadBuf->getRowCapacity());

activeReadBuf->newReadRequest(activeHandle,
orientation,
Expand Down Expand Up @@ -3430,7 +3429,7 @@ double ha_ibmdb2i::read_time(uint index, uint ranges, ha_rows rows)
double dataPageCount = stats.data_file_length/IO_SIZE;

cost = (rows * dataPageCount / totalRecords) +
min(idxPageCnt, (log_2(idxPageCnt) * ranges +
std::min(idxPageCnt, (log_2(idxPageCnt) * ranges +
rows * (log_2(idxPageCnt) + log_2(rows) - log_2(totalRecords))));
}
}
Expand Down Expand Up @@ -3579,7 +3578,7 @@ void ha_ibmdb2i::setIndexReadEstimate(uint index, ha_rows rows)
ha_rows ha_ibmdb2i::getIndexReadEstimate(uint index)
{
if (indexReadSizeEstimates)
return max(indexReadSizeEstimates[index], 1);
return std::max(indexReadSizeEstimates[index], ha_rows{1});

return 10000; // Assume index scan if no estimate exists.
}
Expand Down

0 comments on commit 7f96f1a

Please sign in to comment.