Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db name changes #66

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions centrallix/osdrivers/objdrv_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,65 @@ mysd_internal_BuildAutoname(pMysdData inf, pMysdConn conn, pObjTrxTree oxt)
return rval;
}

/*** mysd_internal_UpdateName() - check an updated row and update the row if need be
***/
int
mysd_internal_UpdateName(pMysdData data, char * newval, int col)
{
int i, j;
char *start, *end;
int curLen;
int newLen;
int fullLen;
int jump;

/** If the updated value is part of a primary key, update the object name **/
for(i = 0 ; i < data->TData->nKeys ; i++)
{
if(data->TData->KeyCols[i] == col && newval)
{

fullLen = strlen(data->Objname);
/* find the start and end of the field to edit*/
start = data->Objname;
for(j = 0 ; j < i ; j++) start = strchr(start, '|')+1;
nboard marked this conversation as resolved.
Show resolved Hide resolved
end = strchr(start, '|') - 1;
if(end == (char*) -1) end = data->Objname + fullLen -1; /* make sure to account for if the string is at the end */

/* check if new item will fit */
curLen = end - start + 1;
newLen = strlen(newval);
if(fullLen - curLen + newLen >= sizeof(data->Objname))
{
mssError(1,"MYSD","Cannot change object '%s' name to include '%s': name exceeds max length.",
data->Objname, newval);
return -1;
}

/* shift over existing items to make room */
jump = newLen - curLen;
if(jump > 0)
nboard marked this conversation as resolved.
Show resolved Hide resolved
{
/* shift data to the right working right to left.
Done once copied to the location right after where the new value will end */
for(j = fullLen + jump ; j > (start - data->Objname) + (newLen - 1); j--)
data->Objname[j] = data->Objname[j-jump];
}
else if(jump < 0)
{
/* shift data to the left, working left to right.
Done once copied to the location where the full string will end */
for(j = start - data->Objname + newLen ; j < fullLen + jump + 1; j++)
data->Objname[j] = data->Objname[j-jump];
}

/* copy over the new value */
for(j = 0 ; j < newLen ; j++) start[j] = newval[j];
nboard marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
return 0;
}

/*** mysd_internal_UpdateRow() - update a given row
***/
Expand Down Expand Up @@ -2974,6 +3033,7 @@ mysdSetAttrValue(void* inf_v, char* attrname, int datatype, pObjData val, pObjTr
int type;
DateTime dt;
ObjData od;
char * valStr;

type = mysdGetAttrType(inf, attrname, oxt);
/** Choose the attr name **/
Expand Down Expand Up @@ -3072,13 +3132,16 @@ mysdSetAttrValue(void* inf_v, char* attrname, int datatype, pObjData val, pObjTr
}
else if(datatype == DATA_T_DOUBLE || datatype == DATA_T_INTEGER)
{
if(mysd_internal_UpdateRow(inf,mysd_internal_CxDataToMySQL(datatype,(ObjData*)val),i) < 0) return -1;
valStr = mysd_internal_CxDataToMySQL(datatype,(ObjData*)val);
if(mysd_internal_UpdateRow(inf,valStr,i) < 0) return -1;
}
else
{
if(mysd_internal_UpdateRow(inf,mysd_internal_CxDataToMySQL(datatype,*(ObjData**)val),i) < 0) return -1;
valStr = mysd_internal_CxDataToMySQL(datatype,*(ObjData**)val);
if(mysd_internal_UpdateRow(inf,valStr,i) < 0) return -1;
}
}
mysd_internal_UpdateName(inf, valStr, i);
}
}
}
Expand Down