Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 1 addition & 39 deletions IscDbc/IscColumnsResultSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,43 +266,6 @@ bool IscColumnsResultSet::nextFetch()
return true;
}

bool IscColumnsResultSet::getDefSource (int indexIn, int indexTarget)
{
if ( sqlda->isNull (indexIn) )
{
sqlda->updateVarying (indexTarget, "NULL");
return false;
}

//XSQLVAR *var = sqlda->Var(indexIn);
auto * var = sqlda->Var( indexIn );
char buffer[1024];
char * beg = buffer + 7; // sizeof("default")
char * end;
int lenRead;

blob.directOpenBlob ((char*)var->sqldata);
blob.directFetchBlob (buffer, 1024, lenRead);
blob.directCloseBlob();

end = buffer + lenRead;

while ( *++beg == ' ' );
while ( *end == ' ' ) end--;

if ( *beg == '\'' && *(beg + 1) != '\'' )
{
++beg;
--end;
}

*end = '\0';

sqlda->updateVarying (indexTarget, beg);

return true;
}

void IscColumnsResultSet::setCharLen (int charLenInd,
int fldLenInd,
IscSqlType &sqlType)
Expand Down Expand Up @@ -415,8 +378,7 @@ void IscColumnsResultSet::adjustResults (IscSqlType &sqlType)
sqlda->updateShort (11, nullable);

// default source
if (!getDefSource (26, 13))
getDefSource (20, 13);
setFieldDefault();

switch (sqlType.type)
{
Expand Down
42 changes: 41 additions & 1 deletion IscDbc/IscColumnsResultSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,54 @@ class IscColumnsResultSet : public IscMetaDataResultSet
IscColumnsResultSet(IscDatabaseMetaData *metaData);
void initResultSet(IscStatement *stmt);
private:
virtual bool getDefSource (int indexIn, int indexTarget);
virtual void setCharLen (int charLenInd, int fldLenInd, IscSqlType &sqlType);
virtual void checkQuotes (IscSqlType &sqlType, JString stringVal);
virtual void adjustResults (IscSqlType &sqlType);

IscBlob blob;
CAttrArray arrAttr;
IscSqlType sqlType;

static constexpr int COLUMN_DEFAULT_TARGET = 13;
static constexpr int COLUMN_DEFAULT_SRC[] = { 26, 20 };
static constexpr char DEFAULT_SIGNATURE[] = "DEFAULT";

inline void setFieldDefault(bool removeQuotes = false)
{
sqlda->updateVarying(COLUMN_DEFAULT_TARGET, "NULL");

for (auto src_fld : COLUMN_DEFAULT_SRC)
{
if (!sqlda->isNull(src_fld))
{
auto* var = sqlda->Var(src_fld);
char buffer[1024];
int lenRead;

blob.directOpenBlob((char*)var->sqldata);
blob.directFetchBlob(buffer, sizeof(buffer) - 1, lenRead);
blob.directCloseBlob();

const char* first = buffer + (strncasecmp(buffer, DEFAULT_SIGNATURE, lenRead) ? 0 : sizeof(DEFAULT_SIGNATURE) - 1);
char* last = buffer + lenRead - 1;

while (*first == ' ') ++first;
while (last > first && *last == ' ') --last;

if (removeQuotes && *first == '\'' && last > first)
{
++first;
if (*last == '\'')
--last;
}

*(last + 1) = '\0';

sqlda->updateVarying(COLUMN_DEFAULT_TARGET, first);
break;
}
}
}
};

}; // end namespace IscDbcLibrary
Expand Down