add replace

pull/1/head
deffpuzzl 2018-05-31 18:28:53 +08:00
parent 2565c4c767
commit 2f5eb0ed4f
21 changed files with 1121 additions and 83 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
demo/drop

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
INCDIR= -I/usr/include -I$(HOME)/include -I./ -I./include -I../include
LIBDIR= -L$(HOME)/lib -L../lib -lstvm -lm -lc -ldl -lpthread
CC=cc -fPIC
CO=-c -g
CO=-c -pg
OUTLIB=../lib
OUTBIN=../bin
@ -18,9 +18,10 @@ EXTREME=extreme
TRUNCATE=truncate
DROP=drop
CLICK=click
REPLACE=replace
PRESSURE=press_demo
all: $(CREATE) $(INSERT) $(SELECT) $(QUERY) $(DELETE) $(UPDATE) $(COUNT) $(GROUP) $(EXTREME) $(TRUNCATE) $(DROP) $(PRESSURE) $(CLICK) clean
all: $(CREATE) $(INSERT) $(SELECT) $(QUERY) $(DELETE) $(UPDATE) $(COUNT) $(GROUP) $(EXTREME) $(TRUNCATE) $(DROP) $(PRESSURE) $(CLICK) $(REPLACE) clean
$(CREATE): create.o
$(CC) -o $@ $< $(LIBDIR)
$(INSERT): insert.o
@ -45,6 +46,8 @@ $(DROP): drop.o
$(CC) -o $@ $< $(LIBDIR)
$(CLICK): click.o
$(CC) -o $@ $< $(LIBDIR)
$(REPLACE): replace.o
$(CC) -o $@ $< $(LIBDIR)
$(PRESSURE): press_demo.o
$(CC) -o $@ $< $(LIBDIR)

Binary file not shown.

Binary file not shown.

View File

@ -27,8 +27,9 @@ long lQueryUserInfo()
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
conditnum(pstSavm, stUser, acct_id, 2018053017);
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180223"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180224"); // 查询条件赋值
if(RC_SUCC != lQuery(pstSavm, &lRow, (void **)&pstUser))
{

Binary file not shown.

View File

@ -26,8 +26,9 @@ long lSelectUserInfo()
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
conditnum(pstSavm, stUser, acct_id, 2018053017); // 查询条件赋值
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180223"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180224"); // 查询条件赋值
if(RC_SUCC != lSelect(pstSavm, (void *)&stUser))
{

Binary file not shown.

Binary file not shown.

View File

@ -33,11 +33,11 @@ typedef long CREATE;
//#pragma pack(4)
#define TVM_VKERNEL "1.2.0.0"
#define TVM_VERSION "1.2.3.0"
#define TVM_VERSION "1.2.4.0"
/*************************************************************************************************
custom macro
*************************************************************************************************/
#define PROT_JAVA 512
#define FIELD_SEL 512
#define FIRST_ROW 256
#define ORDER_DESC 128
#define ORDER_ASC 64
@ -66,6 +66,7 @@ typedef long CREATE;
#define OPERATE_UPDATE 4
#define OPERATE_SELECT 8
#define PROTOCAL_JAVA 512
#define OPERAYS_INSERT 1025
#define OPERAYS_DELETE 1026
#define OPERAYS_UPDATE 1027
@ -112,6 +113,7 @@ typedef long CREATE;
#endif
#define MAX_FIELD_LEN 32 // maxinum length of Field name
#define ALLOC_CMD_LEN 1024 // maxinum length of command
#ifndef MAX_FILED_NUM
#define MAX_FILED_NUM 64 // maximum number of fields in a table
@ -635,6 +637,21 @@ typedef struct __TVM_BOOT_PARAM
char m_szLog[MAX_STRIG_LEN];
}TBoot;
/*************************************************************************************************
STVM user define
*************************************************************************************************/
typedef struct __STVM_CUSTOMIZE
{
Benum m_eDebug;
Benum m_eShow;
long m_lRows;
bool m_bInit;
long m_lKey;
char *m_pszKey;
long m_lWord;
char *m_pszWord;
}TCustom;
/*************************************************************************************************
*************************************************************************************************/
@ -767,6 +784,7 @@ extern long lInsert(SATvm *pstSavm);
extern long lTruncate(SATvm *pstSavm, TABLE t);
extern long lSelect(SATvm *pstSavm, void *psvOut);
extern long lUpdate(SATvm *pstSavm, void *psvUpd);
extern long lReplace(SATvm *pstSavm, void *pvReplace);
extern long lCount(SATvm *pstSavm, size_t *plCount);
extern long lClick(SATvm *pstSavm, ulong *puHits);
extern long lExtreme(SATvm *pstSavm, void *psvOut);

View File

@ -101,9 +101,9 @@ void vDebugTable(TABLE t, long eType)
{
fprintf(stdout, "\n---------------------------- TABLE HEAND INFO ----------------------"
"----------\n");
fprintf(stdout, "TABLE:%9d, extern:%10ld, NAME:%s\t\nSHTree:%8ld, SHList:%10ld, "
fprintf(stdout, "TABLE:%9u, extern:%10ld, NAME:%s\t\nSHTree:%8ld, SHList:%10ld, "
"TblDef:%11ld\nGroup:%9ld, MaxRow:%10ld, Valid:%12ld\nlNodeNil:%6ld, lIType:%10d, "
"Table:%12ld\nIdxLen:%8ld, TreePos:%9ld, TreeRoot:%9d\nGrpLen:%8ld, GroupPos:%8ld, "
"Table:%12ld\nIdxLen:%8ld, TreePos:%9ld, TreeRoot:%9ld\nGrpLen:%8ld, GroupPos:%8ld, "
"GroupRoot:%8ld\nData:%10ld, ReSize:%10ld, Truck:%12ld\nListPos:%7ld, ListOfs:%9ld\n",
((TblDef *)pGetTblDef(t))->m_table, ((TblDef *)pGetTblDef(t))->m_lExtern,
((TblDef *)pGetTblDef(t))->m_szTable, sizeof(SHTree), sizeof(SHList), sizeof(TblDef),
@ -133,7 +133,7 @@ void vDebugTable(TABLE t, long eType)
pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk, pstKey[i].m_szField);
}
fprintf(stdout, "\n--------------------------------UNIQ INDEX FIELD--------------"
fprintf(stdout, "\n-------------------------------CHECK INDEX FIELD--------------"
"----------------\n");
for(i = 0, pstKey = pGetTblGrp(t); i < lGetGrpNum(t); i ++)
{

View File

@ -3,13 +3,14 @@ LIBDIR= -L$(HOME)/lib -L../lib -lstvm -lreadline -lm -lc -ldl -lpthread
AR=ar
LD=ld
LN=ln
CC=cc -fPIC
CO=-c -g -DMAX_INDEX_LEN=64 -DMAX_FILED_NUM=64
#CC=cc -fPIC -O2 -Wno-unused-result -m64 -march=native
CC=cc -fPIC -O2 -Wno-unused-result -march=native
CO=-c -g -O2 -DMAX_INDEX_LEN=64 -DMAX_FILED_NUM=64 -Wno-unused-result
LDFLAG=-shared -g
OUTLIB=../lib
OUTBIN=../bin
OBJFILE=tree.o sem.o msg.o tcp.o str.o list.o conf.o
OBJFILE=tree.o sem.o msg.o tcp.o str.o list.o conf.o queue.o
TARGET=$(OUTLIB)/libstvm.a
TARDLL=$(OUTLIB)/libstvm.so
TARVER=$(OUTLIB)/libstvm.so.1.2

View File

@ -33,7 +33,7 @@
/*************************************************************************************************
function
*************************************************************************************************/
Benum elog = 0;
TCustom g_stCustom;
extern char **environ;
extern long lShutdownTvm();
extern void vSetNode(char *s);
@ -46,7 +46,7 @@ extern long lMountTable(SATvm *pstSavm, char *pszFile);
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
*************************************************************************************************/
static char* sGetTVMVers()
{
struct utsname sinf;
@ -110,7 +110,7 @@ void vSCRDebug(const char *fmt, ...)
char szMsg[1024];
va_list ap;
if(0 == elog) return ;
if(0 == g_stCustom.m_eDebug) return ;
memset(szMsg, 0, sizeof(szMsg));
va_start(ap, fmt);
@ -1183,32 +1183,32 @@ SQLFld* pSortSQLField(SQLFld *pstRoot)
*************************************************************************************************/
long lShowTables(SATvm *pstSavm)
{
char szTable[128];
char szTable[128];
TIndex stIndex, *pstIndex = NULL;
long i, lRows = 0, lTime = lGetTiskTime();
if(RC_SUCC != lInitSATvm(pstSavm, SYS_TVM_INDEX))
return RC_FAIL;
conditinit(pstSavm, stIndex, SYS_TVM_INDEX);
conditinit(pstSavm, stIndex, SYS_TVM_INDEX);
conditnum(pstSavm, stIndex, m_lLocal, RES_LOCAL_SID);
if(RC_SUCC != lQuery(pstSavm, &lRows, (void **)&pstIndex))
return RC_FAIL;
fprintf(stdout, "table table_name\n");
for(i = 0; i < lRows; i ++)
{
memset(szTable, 0, sizeof(szTable));
if(!strcmp(pstIndex[i].m_szPart, pstIndex[i].m_szOwner))
for(i = 0; i < lRows; i ++)
{
memset(szTable, 0, sizeof(szTable));
if(!strcmp(pstIndex[i].m_szPart, pstIndex[i].m_szOwner))
strcpy(szTable, pstIndex[i].m_szTable);
else
else
snprintf(szTable, sizeof(szTable), "%s@%s", pstIndex[i].m_szPart, pstIndex[i].m_szTable);
fprintf(stdout, "%3d %s\n", pstIndex[i].m_table, szTable);
}
}
lTime -= lGetTiskTime();
TFree(pstIndex);
TFree(pstIndex);
fprintf(stdout, "---(%ld) records selected, ep(%d), %s---\n", pstSavm->m_lEffect,
pstSavm->m_lEType, sGetCostTime(-1 * lTime));
return RC_SUCC;
@ -1263,7 +1263,7 @@ void vPrintAmount(int t, char *pszTable, int nValid, int nMax)
void vTableAmount()
{
size_t i, lOut = 0;
char szTable[128];
char szTable[128];
RunTime *pstRun = NULL;
TIndex stIndex, *pstIndex = NULL;
SATvm *pstSavm = (SATvm *)pGetSATvm();
@ -1292,10 +1292,10 @@ void vTableAmount()
if(NULL == (pstRun = pInitHitTest(pstSavm, pstIndex[i].m_table)))
continue;
memset(szTable, 0, sizeof(szTable));
if(!strcmp(pstIndex[i].m_szPart, pstIndex[i].m_szOwner))
memset(szTable, 0, sizeof(szTable));
if(!strcmp(pstIndex[i].m_szPart, pstIndex[i].m_szOwner))
strcpy(szTable, pstIndex[i].m_szTable);
else
else
snprintf(szTable, sizeof(szTable), "%s@%s", pstIndex[i].m_szPart, pstIndex[i].m_szTable);
vPrintAmount(pstIndex[i].m_table, szTable, lGetTblValid(pstIndex[i].m_table),
@ -1308,6 +1308,93 @@ void vTableAmount()
return ;
}
/*************************************************************************************************
descriptionshow table index
parameters
return
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long _lShowTableInfo(SATvm *pstSavm, char *pszTable, bool bRmt)
{
size_t i;
TIndex stIndex;
TblKey *pstKey = NULL;
TField *pstField = NULL;
void *pvWhere = NULL, *pvUpdate = NULL;
memset(&stIndex, 0, sizeof(TIndex));
if(!strlen(pszTable))
{
pstSavm->m_lErrno = SQL_TABLE_NIL;
return RC_FAIL;
}
strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0])
strcpy(stIndex.m_szPart, sGetNode());
if(bRmt)
{
if(RC_SUCC != lTvmGetTblIndex(pstSavm, stIndex.m_szTable, stIndex.m_szPart, &stIndex))
return RC_FAIL;
return RC_FAIL;
}
if(RC_SUCC != lGetTblIndex(pstSavm, stIndex.m_szTable, stIndex.m_szPart, &stIndex))
return RC_FAIL;
if(RC_SUCC != lInitSATvm(pstSavm, stIndex.m_table))
return RC_FAIL;
if(NULL == pInitHitTest(pstSavm, pstSavm->tblName))
{
fprintf(stderr, "hit test table (%d) failed, err:(%d)(%s)\n", stIndex.m_table,
pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return ;
}
if(HAVE_UNIQ_IDX(pstSavm->tblName))
{
fprintf(stdout, "INDEX-NAME:[\033[4;33mUNIQUE\033[0m] "
"INDEX-TYPE:[\033[4;33mRBTREE\033[0m]\n");
pstKey = pGetTblIdx(stIndex.m_table);
for(i = 0; i < lGetIdxNum(pstSavm->tblName); i ++)
{
fprintf(stdout, "FROM:%4ld, LEN:%4ld, ATTR:%ld, FIELD:%s\n", pstKey[i].m_lFrom,
pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_szField);
}
}
if(HAVE_HASH_IDX(pstSavm->tblName) || HAVE_NORL_IDX(pstSavm->tblName))
{
if(HAVE_HASH_IDX(pstSavm->tblName))
{
fprintf(stdout, "\nINDEX-NAME:[\033[4;33mQUERY\033[0m] "
"INDEX-TYPE:[\033[4;33mHASH-LIST]\n");
}
else if(HAVE_NORL_IDX(pstSavm->tblName))
{
fprintf(stdout, "\nINDEX-NAME:[\033[4;33mQUERY\033[0m] "
"INDEX-TYPE:[\033[4;33mRBTREE-LIST\033[0m]\n");
}
pstKey = pGetTblGrp(pstSavm->tblName);
for(i = 0; i < lGetGrpNum(pstSavm->tblName); i ++)
{
fprintf(stdout, "FROM:%4ld, LEN:%4ld, ATTR:%ld, FIELD:%s\n", pstKey[i].m_lFrom,
pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_szField);
}
}
vTblDisconnect(pstSavm, pstSavm->tblName);
return RC_SUCC;
}
/*************************************************************************************************
descriptionPrinting system index
parameters
@ -2221,13 +2308,13 @@ long _lExeSelect(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvD
SQLFld *pstNode = NULL;
Rowgrp *pstList = NULL;
long lTime = lGetTiskTime();
size_t i, lOffset, lRows, lRet;
char szDelmit[64], *pvResult = NULL;
size_t i, lOffset, lRows, lRet, j, k, m;
char szDelmit[64], *pvResult = NULL, *p;
memset(szDelmit, 0, sizeof(szDelmit));
pstSavm->pstVoid = (void *)pvData;
pstSavm->tblName = pstIndex->m_table;
pstSavm->lSize = pstIndex->m_lRowSize;
pstSavm->lSize = pstIndex->m_lRowSize;
if(bRmt)
lRet = lTvmQuery(pstSavm, &lRows, (void **)&pvResult);
else
@ -2243,6 +2330,92 @@ long _lExeSelect(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvD
return RC_FAIL;
}
lTime -= lGetTiskTime();
if(g_stCustom.m_eShow && !pszFile)
{
for(lRet = 0, pstNode = pstRoot; pstNode; pstNode = pstNode->pstNext)
{
if(lRet < strlen(pstNode->m_stKey.m_szField))
lRet = strlen(pstNode->m_stKey.m_szField);
}
for(i = 0, m = 0, ++ lRet; i < lRows && i < pstSavm->m_lEffect; i ++)
{
lOffset = pstIndex->m_lRowSize * i;
for(k = lRet + 20, pstNode = pstRoot; pstNode; pstNode = pstNode->pstNext)
{
pstKey = &pstNode->m_stKey;
switch(pstKey->m_lAttr)
{
case FIELD_DOUB:
switch(pstKey->m_lLen)
{
case 4:
fprintf(stdout, "%-*s:%f\n", lRet, pstNode->m_stKey.m_szField,
*((float *)(pvResult + lOffset + pstKey->m_lFrom)));
break;
case 8:
fprintf(stdout, "%-*s:%f\n", lRet, pstNode->m_stKey.m_szField,
*((double *)(pvResult + lOffset + pstKey->m_lFrom)));
break;
default:
break;
}
break;
case FIELD_LONG:
switch(pstKey->m_lLen)
{
case 2:
fprintf(stdout, "%-*s:%d\n", lRet, pstNode->m_stKey.m_szField,
*((sint *)(pvResult + lOffset + pstKey->m_lFrom)));
break;
case 4:
fprintf(stdout, "%-*s:%d\n", lRet, pstNode->m_stKey.m_szField,
*((int *)(pvResult + lOffset + pstKey->m_lFrom)));
break;
case 8:
fprintf(stdout, "%-*s:%lld\n", lRet, pstNode->m_stKey.m_szField,
*((llong *)(pvResult + lOffset + pstKey->m_lFrom)));
break;
default:
break;
}
break;
case FIELD_CHAR:
if(strlen(pvResult + lOffset + pstKey->m_lFrom) > k)
k = strlen(pvResult + lOffset + pstKey->m_lFrom);
fprintf(stdout, "%-*s:%.*s\n", lRet, pstNode->m_stKey.m_szField,
(int)pstKey->m_lLen, pvResult + lOffset + pstKey->m_lFrom);
break;
default:
break;
}
}
if((i + 1) == lRows) // last row
break;
for(j = 0; j < k; j ++)
fprintf(stdout, "-");
fprintf(stdout, "\n");
if(++ m == g_stCustom.m_lRows) // Total output row number at once
{
m = 0;
fprintf(stdout, "\b\b");
while(10 != getchar());
continue;
}
}
fprintf(stdout, "\n");
fflush(stdout);
TFree(pvResult);
fprintf(stdout, "---(%ld) records selected, ep(%d), %s---\n", pstSavm->m_lEffect,
pstSavm->m_lEType, sGetCostTime(-1 * lTime));
return RC_SUCC;
}
if(pszFile)
{
if(NULL == (fp = fopen(pszFile, "wb")))
@ -2263,7 +2436,7 @@ long _lExeSelect(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvD
fprintf(fp, "%s ", pstNode->m_stKey.m_szField);
fprintf(fp, "\n");
for(i = 0; i < lRows && i < pstSavm->m_lEffect; i ++)
for(m = 0, i = 0; i < lRows && i < pstSavm->m_lEffect; i ++)
{
lOffset = pstIndex->m_lRowSize * i;
for(pstNode = pstRoot; pstNode; pstNode = pstNode->pstNext)
@ -2313,9 +2486,16 @@ long _lExeSelect(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvD
}
fprintf(fp, "\n");
fflush(fp);
if(NULL == pszFile && (++ m) == g_stCustom.m_lRows) // Total output row number at once
{
m = 0;
fprintf(stdout, "\b\b");
while(10 != getchar());
continue;
}
}
TFree(pvResult);
lTime -= lGetTiskTime();
if(pszFile)
{
@ -2343,6 +2523,7 @@ long lParseSequece(SATvm *pstSavm, char *pszSQName, char *pszFiled, bool bRmt
long lRet;
ulong ulSeque;
// select nextval from SEQUENCE@SEQ_TEST
if(strcasecmp(pszFiled, "nextval"))
{
pstSavm->m_lErrno = SQL_ERR_FIELD;
@ -3562,6 +3743,45 @@ long _lUnloadSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
return _lSelectSyntax(pstSavm, p, szFile, szDelmit, bRmt);
}
/**************************************************************************************************
descriptioninitial custom tables
parameters
return
**************************************************************************************************/
void vInitTableList(SATvm *pstSavm, bool bRmt)
{
long lRet;
size_t i, lRows = 0;
TIndex stIndex, *pstIndex = NULL;
pstSavm->bSearch = TYPE_SYSTEM;
// if(RC_SUCC != lInitSATvm(pstSavm, pstFace->m_table))
// return RC_FAIL;
conditinit(pstSavm, stIndex, SYS_TVM_INDEX);
conditnum(pstSavm, stIndex, m_lType, TYPE_CLIENT);
conditnum(pstSavm, stIndex, m_lLocal, RES_LOCAL_SID);
if(bRmt)
lRet = lTvmQuery(pstSavm, (size_t *)&lRows, (void **)&pstIndex);
else
lRet = lQuery(pstSavm, (size_t *)&lRows, (void *)&pstIndex);
if(RC_SUCC != lRet)
return ;
for(i = 0, lRet = strlen(g_stCustom.m_pszWord); i < lRows; i ++)
{
lRet += strlen(pstIndex[i].m_szTable) + 1;
if(lRet > ALLOC_CMD_LEN)
break;
strcat(g_stCustom.m_pszWord, pstIndex[i].m_szTable);
strcat(g_stCustom.m_pszWord, ",");
}
g_stCustom.m_lWord = lgetstrnum(g_stCustom.m_pszWord, ",");
TFree(pstIndex);
return ;
}
/**************************************************************************************************
descriptionParse and execute SQL statements
parameters
@ -3614,6 +3834,8 @@ long lExecuteSQL(SATvm *pstSavm, char *pszSQL)
vTableAmount();
return RC_SUCC;
}
else if(!strncasecmp(pszSQL, "show index from ", 16))
return _lShowTableInfo(pstSavm, pszSQL + 16, false);
else if(!strncasecmp(pszSQL, "comment ", 8))
return _lCommentSyntax(pstSavm, pszSQL + 8, false);
else if(!strncasecmp(pszSQL, "select ", 7))
@ -3685,6 +3907,8 @@ long lExecuteTvm(SATvm *pstSavm, char *pszSQL)
sGetTError(pstSavm->m_lErrno));
return RC_SUCC;
}
else if(!strncasecmp(pszSQL, "show index from ", 16))
return _lShowTableInfo(pstSavm, pszSQL + 16, true);
else if(!strncasecmp(pszSQL, "select ", 7))
return _lSelectSyntax(pstSavm, pszSQL, NULL, NULL, true);
else if(!strncasecmp(pszSQL, "update ", 7))
@ -3892,11 +4116,16 @@ void vAddHistory(char *s)
{
FILE *fp = NULL;
char szPath[512];
static char szCmd[512] = {0};
if(!s || !strlen(s))
return ;
if(!strcmp(szCmd, s))
return ;
memset(szPath, 0, sizeof(szPath));
strncpy(szCmd, s, sizeof(szCmd));
snprintf(szPath, sizeof(szPath), "%s/%s", getenv("TVMDBD"), STVM_SQL_LINE);
if(NULL == (fp = fopen(szPath, "a+")))
return ;
@ -3950,6 +4179,150 @@ void vSetHistory()
rename(szBak, szPath);
}
/**************************************************************************************************
descriptioncustomization
parameters
return
**************************************************************************************************/
void vCustomization(SATvm *pstSavm, char *s)
{
strimall(s);
strimcrlf(s);
if(!strcasecmp(s, "debug on"))
g_stCustom.m_eDebug = 1;
else if(!strcasecmp(s, "debug off"))
g_stCustom.m_eDebug = 0;
else if(!strcasecmp(s, "showmode row"))
g_stCustom.m_eShow = 1;
else if(!strcasecmp(s, "showmode column"))
g_stCustom.m_eShow = 0;
else if(!strncasecmp(s, "showsize ", 9))
g_stCustom.m_lRows = atol(s + 9);
else
{
pstSavm->m_lErrno = SQL_SYNTX_ERR;
fprintf(stderr, "customizing syntax error, (%d)(%s)\n", pstSavm->m_lErrno,
sGetTError(pstSavm->m_lErrno));
}
return ;
}
/*************************************************************************************************
descriptionGet the key from matches list
parameters
pszText --user text
nPos --last pos
return
char*
*************************************************************************************************/
char* sCommandKey(const char *pszText, int nPos)
{
static int i;
char szKey[64];
for(i = nPos == 0 ? 0 : i; i < g_stCustom.m_lKey; i ++)
{
memset(szKey, 0, sizeof(szKey));
strncpy(szKey, sfieldvalue(g_stCustom.m_pszKey, ",", i + 1), sizeof(szKey));
if(!strncasecmp(szKey, pszText, strlen(pszText)))
{
i ++;
return strdup(szKey);
}
}
return NULL;
}
/*************************************************************************************************
descriptionGet the word from matches list
parameters
pszText --user text
nPos --last pos
return
char*
*************************************************************************************************/
char* sCommandWord(const char *pszText, int nPos)
{
static int i;
char szWord[64];
for(i = nPos == 0 ? 0 : i; i < g_stCustom.m_lWord; i ++)
{
memset(szWord, 0, sizeof(szWord));
strncpy(szWord, sfieldvalue(g_stCustom.m_pszWord, ",", i + 1), sizeof(szWord));
if(!strncasecmp(szWord, pszText, strlen(pszText)))
{
i ++;
return strdup(szWord);
}
}
return NULL;
}
/*************************************************************************************************
descriptionGet the matches list
parameters
pszCmd --user text
return
char*
*************************************************************************************************/
char **pMatchCompletion(const char *pszCmd, int nPos, int nEnd)
{
char **ppszMatch = NULL;
if(NULL == pszCmd || !strlen(pszCmd))
return NULL;
if(nPos == 0)
ppszMatch = rl_completion_matches(pszCmd, sCommandKey);
else
ppszMatch = rl_completion_matches(pszCmd, sCommandWord);
return ppszMatch;
}
/**************************************************************************************************
descriptioninitial custom
parameters
return
**************************************************************************************************/
void vInitialCustom()
{
memset(&g_stCustom, 0, sizeof(TCustom));
g_stCustom.m_eDebug = 0;
g_stCustom.m_eShow = 0; // 显示模式 记录为单位,行为单位
g_stCustom.m_lRows = 1;
g_stCustom.m_bInit = false;
g_stCustom.m_lKey = 0;
g_stCustom.m_lWord = 0;
g_stCustom.m_pszKey = NULL;
g_stCustom.m_pszWord = NULL;
g_stCustom.m_pszKey = (char *)calloc(1, ALLOC_CMD_LEN);
g_stCustom.m_pszWord = (char *)calloc(1, ALLOC_CMD_LEN);
if(NULL == g_stCustom.m_pszKey || NULL == g_stCustom.m_pszWord)
exit(-1);
snprintf(g_stCustom.m_pszKey, ALLOC_CMD_LEN, "SELECT,INSERT,"
"UPDATE,DELETE,DROP,RENAME,TRUNCATE,REPLACE,CLEAR,EXIT,CREATE,BEGIN WORK,"
"END WORK,COMMIT WORK,ROLLBACK WORK,SHOW,COMMENT,LOAD,UNLOAD,SET,");
g_stCustom.m_lKey = lgetstrnum(g_stCustom.m_pszKey, ",");
//select nextval from SEQUENCE@SEQ_TEST
snprintf(g_stCustom.m_pszWord, ALLOC_CMD_LEN, "SET,FROM,WHERE,"
"COUNT(1),MAX,MIN,NEXTVAL,ORDER BY,GROUP BY,SEQUENCE@,SYS_TVM_FIELD,"
"SYS_TVM_DOMAIN,SYS_TVM_SEQUE,TABLES,INTO,INFO,INDEX,VALUES,DEBUG [ON|OFF],"
"SHOWMODE [ROW|COLUMN],SHOWSIZE [NUM],");
g_stCustom.m_lWord = lgetstrnum(g_stCustom.m_pszWord, ",");
rl_attempted_completion_function = pMatchCompletion;
return ;
}
/**************************************************************************************************
descriptionExecute SQL functions
parameters
@ -3965,10 +4338,18 @@ void vSQLStatement(int argc, char *argv[])
system("stty erase ^?");
system("stty erase ^H");
fprintf(stdout, "\n%s\n", sFuncVersion());
vInitialCustom();
// initialize_readline();
for(i = 2; i < argc; i ++)
{
if(!strcasecmp(argv[i], "--debug=on"))
elog = 1;
g_stCustom.m_eDebug = 1;
else if(!strcasecmp(argv[i], "--showmode=row"))
g_stCustom.m_eShow = 1;
else if(!strcasecmp(argv[i], "--showmode=column"))
g_stCustom.m_eShow = 0;
else if(!strncasecmp(argv[i], "--showsize=", 11))
g_stCustom.m_lRows = atol(argv[i] + 11);
else if(!strncasecmp(argv[i], "--msql=", 7))
{
if(NULL == (fp = fopen(argv[i] + 7, "rb")))
@ -4010,6 +4391,7 @@ void vSQLStatement(int argc, char *argv[])
}
vSetHistory();
vInitTableList(pstSavm, lRemote > 0 ? true : false);
while(1)
{
if(fp)
@ -4030,6 +4412,7 @@ void vSQLStatement(int argc, char *argv[])
continue;
}
srtrim(szSQL);
if(!strcmp(pszUser, "q") || !strcmp(pszUser, "Q") || !strcmp(pszUser, "exit"))
break;
@ -4039,6 +4422,15 @@ void vSQLStatement(int argc, char *argv[])
TFree(pszUser);
continue;
}
else if(!strncasecmp(pszUser, "set ", 4))
{
vCustomization(pstSavm, pszUser + 4);
fprintf(stdout, "\n\n\n");
add_history(pszUser);
vAddHistory(pszUser);
TFree(pszUser);
continue;
}
else if(!strncasecmp(pszUser, "create", 6))
{
if(lRemote > 0)
@ -4465,14 +4857,14 @@ int main(int argc, char *argv[])
fprintf(stderr, "rebuild index failure, %s\n", sGetTError(pstSavm->m_lErrno));
return RC_SUCC;
case 'l':
fprintf(stdout, "Do you want to initialize the lock of table (%d) Y/N?:", atol(optarg));
fprintf(stdout, "Do you want to initialize the lock of table (%ld) Y/N?:", atol(optarg));
lRet = getchar();
if(0x59 != lRet && 0x79 != lRet)
return RC_SUCC;
if(RC_SUCC != lResetLock(pstSavm, atol(optarg)))
fprintf(stderr, "重置表(%d)失败, %s\n", atol(optarg), sGetTError(pstSavm->m_lErrno));
fprintf(stderr, "重置表(%ld)失败, %s\n", atol(optarg), sGetTError(pstSavm->m_lErrno));
else
fprintf(stderr, "重置表(%d)完成, completed successfully !!\n", atol(optarg));
fprintf(stderr, "重置表(%ld)完成, completed successfully !!\n", atol(optarg));
return RC_SUCC;
case 'v':
fprintf(stdout, "%s\n", sGetTVMVers());

View File

@ -1757,9 +1757,9 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi
}
}
if(PROT_JAVA & pstFace->m_enum)
if(PROTOCAL_JAVA & pstFace->m_enum)
{
pstFace->m_enum = pstFace->m_enum ^ PROT_JAVA;
pstFace->m_enum = pstFace->m_enum ^ PROTOCAL_JAVA;
pstFace->m_lDLen = pstRun->m_lRowSize;
if(NULL == (pvData = pProtocaJava(pstSovm, pstVoid, pstFace, pvData, pstFace->m_lRows)))
{

View File

@ -5485,7 +5485,7 @@ long _lSelectIndex(SATvm *pstSavm, void *pvAddr, TABLE t, void *psvOut, size_
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pstSavm->pstVoid))
{
pthread_rwlock_unlock(prwLock);
pstSavm->m_lErrno = SVR_EXCEPTION;
pstSavm->m_lErrno = NO_DATA_FOUND;
return RC_FAIL;
}
@ -5916,7 +5916,7 @@ long _lQueryIndex(SATvm *pstSavm, void *pvAddr, TABLE t, size_t *plOut, void
pstTruck = (PSHTruck)pGetNode(pvAddr, pstTree->m_lData);
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pstSavm->pstVoid))
{
pstSavm->m_lErrno = SVR_EXCEPTION;
pstSavm->m_lErrno = NO_DATA_FOUND;
return RC_FAIL;
}
@ -6443,6 +6443,12 @@ long __lInsert(SATvm *pstSavm, void *pvAddr, TABLE t, ulong uTimes)
{
SHTruck *pstTruck = NULL;
if(lGetTblRow(pstSavm->tblName) <= ((TblDef *)pvAddr)->m_lValid)
{
pstSavm->m_lErrno = DATA_SPC_FULL;
return RC_FAIL;
}
if(HAVE_UNIQ_IDX(t))
{
if(RC_SUCC != _lInsertIndex(pstSavm, pvAddr, t, &pstTruck))
@ -6535,14 +6541,6 @@ long lInsert(SATvm *pstSavm)
return RC_FAIL;
}
if(lGetTblRow(pstSavm->tblName) <= ((TblDef *)pstRun->m_pvAddr)->m_lValid)
{
pthread_rwlock_unlock(prwLock);
pstSavm->m_lErrno = DATA_SPC_FULL;
vTblDisconnect(pstSavm, pstSavm->tblName);
return RC_FAIL;
}
lRet = __lInsert(pstSavm, pstRun->m_pvAddr, pstSavm->tblName, 0);
pthread_rwlock_unlock(prwLock);
vTblDisconnect(pstSavm, pstSavm->tblName);
@ -6678,7 +6676,7 @@ long _llFetchIndex(SATvm *pstSavm, RunTime *pstRun, TABLE t, void *psvOut)
pstTruck = (PSHTruck)pGetNode(pvAddr, pstTree->m_lData);
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pstRun->pstVoid))
{
pstSavm->m_lErrno = SVR_EXCEPTION;
pstSavm->m_lErrno = NO_DATA_FOUND;
return RC_FAIL;
}
@ -7064,7 +7062,7 @@ long _lNextIndex(SATvm *pstSavm, RunTime *pstRun, TABLE t, void **ppvOAddr)
pstTruck = (PSHTruck)pGetNode(pvAddr, pstTree->m_lData);
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pstRun->pstVoid))
{
pstSavm->m_lErrno = SVR_EXCEPTION;
pstSavm->m_lErrno = NO_DATA_FOUND;
return RC_FAIL;
}
@ -7394,7 +7392,7 @@ long __lIndexUpdate(SATvm *pstSavm, void *pvAddr, TABLE t, SHTruck *pstTruck,
pstSavm --stvm handle
pstAddr --table handle
t --table
pvUpdate --update date
pvUpdate --update data
return:
RC_SUCC --success
RC_FAIL --failure
@ -7448,14 +7446,13 @@ long _lUpdateIndex(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pstSavm->pstVoid))
{
pthread_rwlock_unlock(prwLock);
pstSavm->m_lErrno = SVR_EXCEPTION;
pstSavm->m_lErrno = NO_DATA_FOUND;
TFree(pvData);
return RC_FAIL;
}
memcpy(pvData, pvUpdate, lGetRowSize(pstSavm->tblName));
memcpy(pvUpdate, pstTruck->m_pvData, lGetRowSize(pstSavm->tblName));
if(RC_FAIL == lMergeTruck(pstSavm, &pstSavm->stUpdt, pvData, pvUpdate))
memcpy(pvData, pstTruck->m_pvData, lGetRowSize(pstSavm->tblName));
if(RC_FAIL == lMergeTruck(pstSavm, &pstSavm->stUpdt, pvUpdate, pvData))
{
pthread_rwlock_unlock(prwLock);
TFree(pvData);
@ -7463,7 +7460,7 @@ long _lUpdateIndex(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
}
memset(szIdx, 0, sizeof(szIdx));
if(NULL == pPickIndex(lGetIdxNum(t), pGetTblIdx(t), pvUpdate, szIdx))
if(NULL == pPickIndex(lGetIdxNum(t), pGetTblIdx(t), pvData, szIdx))
{
pthread_rwlock_unlock(prwLock);
pstSavm->m_lErrno = IDX_FIELD_NIL;
@ -7471,7 +7468,7 @@ long _lUpdateIndex(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
return RC_FAIL;
}
pstSavm->pstVoid = pvUpdate;
pstSavm->pstVoid = pvData;
pstTruck->m_lTimes ++;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NULL);
if(!memcmp(szIdx, szOld, MAX_INDEX_LEN))
@ -7532,7 +7529,7 @@ long _lUpdateIndex(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
return RC_FAIL;
}
memcpy(pstTruck->m_pvData, pvUpdate, lGetRowSize(t));
memcpy(pstTruck->m_pvData, pvData, lGetRowSize(t));
pthread_rwlock_unlock(prwLock);
pstSavm->m_lEffect = 1;
@ -7546,7 +7543,7 @@ long _lUpdateIndex(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
pstSavm --stvm handle
pstAddr --table handle
t --table
pvUpdate --update date
pvUpdate --update data
return:
RC_SUCC --success
RC_FAIL --failure
@ -7581,13 +7578,13 @@ long _lUpdateGroup(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
if(NULL == (pstRoot = (SHTree *)pGetNode(pvAddr, ((TblDef *)pvAddr)->m_lGroupRoot)))
{
pstSavm->m_lErrno = SVR_EXCEPTION;
goto GROUP_ERROR;
goto REPGROUP_ERROR;
}
if(NULL == (pstTree = pSearchTree(pvAddr, pstRoot, szOld, lGetGrpLen(t))))
{
pstSavm->m_lErrno = NO_DATA_FOUND;
goto GROUP_ERROR;
goto REPGROUP_ERROR;
}
pstSavm->m_lEffect = 0;
@ -7606,13 +7603,13 @@ long _lUpdateGroup(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
memcpy(pvData, pstTruck->m_pvData, lGetRowSize(t));
if(RC_FAIL == lMergeTruck(pstSavm, &pstSavm->stUpdt, pvUpdate, pvData))
goto GROUP_ERROR;
goto REPGROUP_ERROR;
memset(szIdx, 0, sizeof(szIdx));
if(NULL == pPickIndex(lGetGrpNum(t), pGetTblGrp(t), pvData, szIdx))
{
pstSavm->m_lErrno = IDX_FIELD_NIL;
goto GROUP_ERROR;
goto REPGROUP_ERROR;
}
pstSavm->m_lEffect ++;
@ -7623,7 +7620,7 @@ long _lUpdateGroup(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
if(RC_SUCC != __lIndexUpdate(pstSavm, pvAddr, t, pstTruck, pstList->m_lData))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto GROUP_ERROR;
goto REPGROUP_ERROR;
}
}
@ -7636,7 +7633,7 @@ long _lUpdateGroup(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
((TblDef *)pvAddr)->m_lValid ++;
pstSavm->m_lErrno = SVR_EXCEPTION;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto GROUP_ERROR;
goto REPGROUP_ERROR;
}
if(SELF_POS_UNUSE == pstTree->m_lData)
@ -7648,7 +7645,7 @@ long _lUpdateGroup(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
if(NULL == (pstRoot = pInsertGroup(pstSavm, pstRoot, szIdx, lGetGrpLen(t), &pstTruck)))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto GROUP_ERROR;
goto REPGROUP_ERROR;
}
((TblDef *)pvAddr)->m_lValid ++;
@ -7656,7 +7653,7 @@ long _lUpdateGroup(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
}
if(RC_SUCC != lRecordWork(pstSavm, pstTruck->m_pvData, OPERATE_UPDATE))
goto GROUP_ERROR;
goto REPGROUP_ERROR;
memcpy(pstTruck->m_pvData, pvData, lGetRowSize(t));
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
@ -7674,7 +7671,7 @@ long _lUpdateGroup(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
return RC_SUCC;
GROUP_ERROR:
REPGROUP_ERROR:
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_FAIL;
@ -7686,7 +7683,7 @@ GROUP_ERROR:
pstSavm --stvm handle
pstAddr --table handle
t --table
pvUpdate --update date
pvUpdate --update data
return:
RC_SUCC --success
RC_FAIL --failure
@ -7743,13 +7740,13 @@ long _lUpdateHash(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
memcpy(pvData, pstTruck->m_pvData, lGetRowSize(t));
if(RC_FAIL == lMergeTruck(pstSavm, &pstSavm->stUpdt, pvUpdate, pvData))
goto HASH_ERROR;
goto REPHASH_ERROR;
memset(szIdx, 0, sizeof(szIdx));
if(NULL == pPickIndex(lGetGrpNum(t), pGetTblGrp(t), pvData, szIdx))
{
pstSavm->m_lErrno = IDX_FIELD_NIL;
goto HASH_ERROR;
goto REPHASH_ERROR;
}
pstSavm->m_lEffect ++;
@ -7761,7 +7758,7 @@ long _lUpdateHash(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
if(RC_SUCC != __lIndexUpdate(pstSavm, pvAddr, t, pstTruck, pstList->m_lData))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NULL);
goto HASH_ERROR;
goto REPHASH_ERROR;
}
}
@ -7775,7 +7772,7 @@ long _lUpdateHash(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
((TblDef *)pvAddr)->m_lValid ++;
pstSavm->m_lErrno = SVR_EXCEPTION;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto HASH_ERROR;
goto REPHASH_ERROR;
}
lOffset = ((TblDef *)pvAddr)->m_lGroupPos + lIdx * sizeof(SHTree);
@ -7783,20 +7780,20 @@ long _lUpdateHash(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
{
pstSavm->m_lErrno = SVR_EXCEPTION;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto HASH_ERROR;
goto REPHASH_ERROR;
}
if(RC_SUCC != __lInsertHash(pstSavm, pvAddr, t, pstTree, lOffset, &pstTruck))
{
pstSavm->m_lErrno = SVR_EXCEPTION;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto HASH_ERROR;
goto REPHASH_ERROR;
}
((TblDef *)pvAddr)->m_lValid ++;
}
if(RC_SUCC != lRecordWork(pstSavm, pstTruck->m_pvData, OPERATE_UPDATE))
goto HASH_ERROR;
goto REPHASH_ERROR;
memcpy(pstTruck->m_pvData, pvData, lGetRowSize(t));
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
@ -7814,7 +7811,7 @@ long _lUpdateHash(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
return RC_SUCC;
HASH_ERROR:
REPHASH_ERROR:
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_FAIL;
@ -7826,7 +7823,7 @@ HASH_ERROR:
pstSavm --stvm handle
pstAddr --table handle
t --table
pvUpdate --update date
pvUpdate --update data
return:
RC_SUCC --success
RC_FAIL --failure
@ -7924,7 +7921,7 @@ TRUCK_ERROR:
descriptionAPI - Update
parameters:
pstSavm --stvm handle
pvUpdate --update date
pvUpdate --update data
return:
RC_SUCC --success
RC_FAIL --failure
@ -8742,7 +8739,7 @@ long _lExportContext(FILE *fp, char *s, long lIdx, TblKey *pstIdx, char *f)
}
break;
case FIELD_CHAR:
fprintf(fp, "%.*s", pstIdx[i].m_lLen, s + pstIdx[i].m_lFrom);
fprintf(fp, "%.*s", (int)pstIdx[i].m_lLen, s + pstIdx[i].m_lFrom);
break;
default:
fprintf(stderr, "Export field attribute exception\n");
@ -9737,7 +9734,7 @@ long _lClickIndex(SATvm *pstSavm, void *pvAddr, TABLE t, ulong *puHits)
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pstSavm->pstVoid))
{
pthread_rwlock_unlock(prwLock);
pstSavm->m_lErrno = SVR_EXCEPTION;
pstSavm->m_lErrno = NO_DATA_FOUND;
return RC_FAIL;
}
@ -10016,6 +10013,631 @@ long lClick(SATvm *pstSavm, ulong *puHits)
return lRet;
}
/*************************************************************************************************
descriptionSelect the table data according to the Unique index
parameters:
pstSavm --stvm handle
pvAddr --memory address
t --table
psvOut --result data
plData --offset
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long _lReplaceIndex(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
{
size_t lData;
long lRet = RC_SUCC;
void *pvData = NULL;
SHTruck *pstTruck = NULL;
SHTree *pstRoot, *pstTree = NULL;
RWLock *prwLock = (RWLock *)pGetRWLock(pvAddr);
char szOld[MAX_INDEX_LEN], szIdx[MAX_INDEX_LEN];
memset(szOld, 0, sizeof(szOld));
if(NULL == pGetIndex(&pstSavm->stCond, lGetIdxNum(t), pGetTblIdx(t), pstSavm->pstVoid, szOld))
return RC_CONTU;
if(NULL == (pvData = (void *)malloc(lGetRowSize(pstSavm->tblName))))
{
pstSavm->m_lErrno = MALLC_MEM_ERR;
return RC_FAIL;
}
if(RC_SUCC != pthread_rwlock_wrlock(prwLock))
{
pstSavm->m_lErrno = LOCK_DOWR_ERR;
TFree(pvData);
return RC_FAIL;
}
pstSavm->m_lEType = EXE_PLAN_IDX;
if(NULL == (pstRoot = (SHTree *)pGetNode(pvAddr, ((TblDef *)pvAddr)->m_lTreeRoot)))
{
pthread_rwlock_unlock(prwLock);
pstSavm->m_lErrno = SVR_EXCEPTION;
TFree(pvData);
return RC_FAIL;
}
if(NULL == (pstTree = (SHTree *)pSearchTree(pvAddr, pstRoot, szOld, lGetIdxLen(t))))
{
// If don't find it, so insert
pstSavm->pstVoid = pvUpdate;
lRet = __lInsert(pstSavm, pvAddr, t, 0);
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return lRet;
}
lData = pstTree->m_lData;
pstTruck = (PSHTruck)pGetNode(pvAddr, pstTree->m_lData);
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pstSavm->pstVoid))
{
pthread_rwlock_unlock(prwLock);
// The uniq index is same, and the new data must trigger the index repetition.
pstSavm->m_lErrno = UNIQ_IDX_REPT;
TFree(pvData);
return RC_FAIL;
}
memcpy(pvData, pstTruck->m_pvData, lGetRowSize(pstSavm->tblName));
if(RC_FAIL == lMergeTruck(pstSavm, &pstSavm->stUpdt, pvUpdate, pvData))
{
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_FAIL;
}
memset(szIdx, 0, sizeof(szIdx));
if(NULL == pPickIndex(lGetIdxNum(t), pGetTblIdx(t), pvData, szIdx))
{
pthread_rwlock_unlock(prwLock);
pstSavm->m_lErrno = IDX_FIELD_NIL;
TFree(pvData);
return RC_FAIL;
}
pstSavm->pstVoid = pvData;
pstTruck->m_lTimes ++;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NULL);
if(!memcmp(szIdx, szOld, MAX_INDEX_LEN))
{
if(HAVE_NORL_IDX(t))
lRet = __lUpdateGroup(pstSavm, pvAddr, t, pstTruck, lData);
else if(HAVE_HASH_IDX(t))
lRet = __lUpdateHash(pstSavm, pvAddr, t, pstTruck, lData);
}
else
{
if(NULL != (SHTree *)pSearchTree(pvAddr, pstRoot, szIdx, lGetIdxLen(t)))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
pthread_rwlock_unlock(prwLock);
pstSavm->m_lErrno = UNIQ_IDX_REPT;
TFree(pvData);
return RC_FAIL;
}
if(NULL == (pstRoot = _pDeleteTree(pvAddr, pstSavm->tblName, pstRoot, pstTree)))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
pthread_rwlock_unlock(prwLock);
pstSavm->m_lErrno = SVR_EXCEPTION;
TFree(pvData);
return RC_FAIL;
}
((TblDef *)pvAddr)->m_lValid --;
if(NULL == (pstRoot = pInsertTree(pstSavm, pstRoot, szIdx, lGetIdxLen(t), &pstTruck)))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_FAIL;
}
((TblDef *)pvAddr)->m_lValid ++;
((TblDef *)pvAddr)->m_lTreeRoot = pstRoot->m_lSePos;
if(HAVE_NORL_IDX(t))
lRet = __lUpdateGroup(pstSavm, pvAddr, t, pstTruck, lData);
else if(HAVE_HASH_IDX(t))
lRet = __lUpdateHash(pstSavm, pvAddr, t, pstTruck, lData);
}
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
if(RC_SUCC != lRet)
{
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_FAIL;
}
if(RC_SUCC != lRecordWork(pstSavm, pstTruck->m_pvData, OPERATE_UPDATE))
{
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_FAIL;
}
memcpy(pstTruck->m_pvData, pvData, lGetRowSize(t));
pthread_rwlock_unlock(prwLock);
pstSavm->m_lEffect = 1;
TFree(pvData);
return RC_SUCC;
}
/*************************************************************************************************
descriptionUpdate record index
parameters:
pstSavm --stvm handle
pstAddr --table handle
t --table
pvUpdate --update data
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long _lReplaceGroup(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
{
SHList *pstList = NULL;
SHTruck *pstTruck = NULL;
size_t lOffset, lNext;
SHTree *pstTree, *pstRoot;
void *pvData, *pvCond = NULL;
RWLock *prwLock = (RWLock *)pGetRWLock(pvAddr);
char szOld[MAX_INDEX_LEN], szIdx[MAX_INDEX_LEN];
memset(szOld, 0, sizeof(szOld));
if(NULL == pGetIndex(&pstSavm->stCond, lGetGrpNum(t), pGetTblGrp(t), pstSavm->pstVoid, szOld))
return RC_CONTU;
if(NULL == (pvData = (void *)malloc(lGetRowSize(t))))
{
pstSavm->m_lErrno = MALLC_MEM_ERR;
return RC_FAIL;
}
if(RC_SUCC != pthread_rwlock_wrlock(prwLock))
{
pstSavm->m_lErrno = LOCK_DOWR_ERR;
TFree(pvData);
return RC_FAIL;
}
if(NULL == (pstRoot = (SHTree *)pGetNode(pvAddr, ((TblDef *)pvAddr)->m_lGroupRoot)))
{
pstSavm->m_lErrno = SVR_EXCEPTION;
goto GROUP_ERROR;
}
if(NULL == (pstTree = pSearchTree(pvAddr, pstRoot, szOld, lGetGrpLen(t))))
{
TFree(pvData);
// If don't find it, then insert
pstSavm->pstVoid = pvUpdate;
lNext = __lInsert(pstSavm, pvAddr, t, 0);
pthread_rwlock_unlock(prwLock);
return lNext;
}
pstSavm->m_lEffect = 0;
pvCond = pstSavm->pstVoid;
pstSavm->m_lEType = EXE_PLAN_GRP;
for(pstList = (SHList *)pGetNode(pvAddr, pstTree->m_lData); SELF_POS_UNUSE != pstList->m_lPos;
pstList = (SHList *)pGetNode(pvAddr, lNext))
{
lNext = pstList->m_lNext;
pstTruck = (PSHTruck)pGetNode(pvAddr, pstList->m_lData);
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pvCond))
{
if(SELF_POS_UNUSE == pstList->m_lNext) break;
continue;
}
memcpy(pvData, pstTruck->m_pvData, lGetRowSize(t));
if(RC_FAIL == lMergeTruck(pstSavm, &pstSavm->stUpdt, pvUpdate, pvData))
goto GROUP_ERROR;
memset(szIdx, 0, sizeof(szIdx));
if(NULL == pPickIndex(lGetGrpNum(t), pGetTblGrp(t), pvData, szIdx))
{
pstSavm->m_lErrno = IDX_FIELD_NIL;
goto GROUP_ERROR;
}
pstSavm->m_lEffect ++;
pstSavm->pstVoid = pvData;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NULL);
if(HAVE_UNIQ_IDX(t))
{
if(RC_SUCC != __lIndexUpdate(pstSavm, pvAddr, t, pstTruck, pstList->m_lData))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto GROUP_ERROR;
}
}
if(memcmp(szIdx, szOld, MAX_INDEX_LEN))
{
-- ((TblDef *)pvAddr)->m_lValid;
lOffset = lGetListOfs(t) + ((TblDef *)pvAddr)->m_lValid * sizeof(SHList);
if(RC_SUCC != lReleaseList(pvAddr, t, pstTree, pstList, lOffset, &lNext))
{
((TblDef *)pvAddr)->m_lValid ++;
pstSavm->m_lErrno = SVR_EXCEPTION;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto GROUP_ERROR;
}
if(SELF_POS_UNUSE == pstTree->m_lData)
{
pstRoot = _pDeleteGroup(pvAddr, t, pstRoot, pstTree, &pstSavm->m_lEffect);
((TblDef *)pvAddr)->m_lGroupRoot = pstRoot->m_lSePos;
}
if(NULL == (pstRoot = pInsertGroup(pstSavm, pstRoot, szIdx, lGetGrpLen(t), &pstTruck)))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto GROUP_ERROR;
}
((TblDef *)pvAddr)->m_lValid ++;
((TblDef *)pvAddr)->m_lGroupRoot = pstRoot->m_lSePos;
}
if(RC_SUCC != lRecordWork(pstSavm, pstTruck->m_pvData, OPERATE_UPDATE))
goto GROUP_ERROR;
memcpy(pstTruck->m_pvData, pvData, lGetRowSize(t));
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
if(FIRST_ROW & pstSavm->lFind) break;
}
if(0 == pstSavm->m_lEffect)
{
// If don't find it, then insert
pstSavm->pstVoid = pvUpdate;
lNext = __lInsert(pstSavm, pvAddr, t, 0);
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return lNext;
}
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_SUCC;
GROUP_ERROR:
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_FAIL;
}
/*************************************************************************************************
descriptionUpdate record hash index
parameters:
pstSavm --stvm handle
pstAddr --table handle
t --table
pvUpdate --update data
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long _lReplaceHash(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
{
SHList *pstList = NULL;
SHTruck *pstTruck = NULL;
SHTree *pstTree, *pstHash;
void *pvData = NULL, *pvCond;
size_t lOld, lIdx, lOffset, lNext;
RWLock *prwLock = (RWLock *)pGetRWLock(pvAddr);
char szOld[MAX_INDEX_LEN], szIdx[MAX_INDEX_LEN];
memset(szOld, 0, sizeof(szOld));
if(NULL == pGetIndex(&pstSavm->stCond, lGetGrpNum(t), pGetTblGrp(t), pstSavm->pstVoid, szOld))
return RC_CONTU;
if(NULL == (pvData = (void *)malloc(lGetRowSize(t))))
{
pstSavm->m_lErrno = MALLC_MEM_ERR;
return RC_FAIL;
}
lOld = uGetHash(szOld, lGetGrpLen(t)) % ((TblDef *)pvAddr)->m_lMaxRow;
lOffset = ((TblDef *)pvAddr)->m_lGroupPos + lOld * sizeof(SHTree);
if(RC_SUCC != pthread_rwlock_wrlock(prwLock))
{
pstSavm->m_lErrno = LOCK_DOWR_ERR;
TFree(pvData);
return RC_FAIL;
}
if(NULL == (pstHash = (SHTree *)(pvAddr + lOffset)))
{
// If don't find it, then insert
pstSavm->pstVoid = pvUpdate;
lNext = __lInsert(pstSavm, pvAddr, t, 0);
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return lNext;
}
pstSavm->m_lEffect = 0;
pvCond = pstSavm->pstVoid;
pstSavm->m_lEType = EXE_PLAN_GRP;
for(pstList = (SHList *)pGetNode(pvAddr, pstHash->m_lData); SELF_POS_UNUSE != pstList->m_lPos;
pstList = (SHList *)pGetNode(pvAddr, lNext))
{
lNext = pstList->m_lNext;
pstTruck = (PSHTruck)pGetNode(pvAddr, pstList->m_lData);
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pvCond))
{
if(SELF_POS_UNUSE == pstList->m_lNext) break;
continue;
}
memcpy(pvData, pstTruck->m_pvData, lGetRowSize(t));
if(RC_FAIL == lMergeTruck(pstSavm, &pstSavm->stUpdt, pvUpdate, pvData))
goto HASH_ERROR;
memset(szIdx, 0, sizeof(szIdx));
if(NULL == pPickIndex(lGetGrpNum(t), pGetTblGrp(t), pvData, szIdx))
{
pstSavm->m_lErrno = IDX_FIELD_NIL;
goto HASH_ERROR;
}
pstSavm->m_lEffect ++;
pstSavm->pstVoid = pvData;
lIdx = uGetHash(szIdx, lGetGrpLen(t)) % ((TblDef *)pvAddr)->m_lMaxRow;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NULL);
if(HAVE_UNIQ_IDX(t))
{
if(RC_SUCC != __lIndexUpdate(pstSavm, pvAddr, t, pstTruck, pstList->m_lData))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NULL);
goto HASH_ERROR;
}
}
// Index does not match, rebuild inde
if(lOld != lIdx)
{
-- ((TblDef *)pvAddr)->m_lValid;
lOffset = lGetListOfs(t) + ((TblDef *)pvAddr)->m_lValid * sizeof(SHList);
if(RC_SUCC != lReleaseList(pvAddr, t, pstHash, pstList, lOffset, &lNext))
{
((TblDef *)pvAddr)->m_lValid ++;
pstSavm->m_lErrno = SVR_EXCEPTION;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto HASH_ERROR;
}
lOffset = ((TblDef *)pvAddr)->m_lGroupPos + lIdx * sizeof(SHTree);
if(NULL == (pstTree = (SHTree *)(pvAddr + lOffset)))
{
pstSavm->m_lErrno = SVR_EXCEPTION;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto HASH_ERROR;
}
if(RC_SUCC != __lInsertHash(pstSavm, pvAddr, t, pstTree, lOffset, &pstTruck))
{
pstSavm->m_lErrno = SVR_EXCEPTION;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto HASH_ERROR;
}
((TblDef *)pvAddr)->m_lValid ++;
}
if(RC_SUCC != lRecordWork(pstSavm, pstTruck->m_pvData, OPERATE_UPDATE))
goto HASH_ERROR;
memcpy(pstTruck->m_pvData, pvData, lGetRowSize(t));
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
if(FIRST_ROW & pstSavm->lFind) break;
}
if(0 == pstSavm->m_lEffect)
{
// If don't find it, then insert
pstSavm->pstVoid = pvUpdate;
lNext = __lInsert(pstSavm, pvAddr, t, 0);
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return lNext;
}
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_SUCC;
HASH_ERROR:
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_FAIL;
}
/*************************************************************************************************
descriptionUpdate record truck
parameters:
pstSavm --stvm handle
pstAddr --table handle
t --table
pvUpdate --update data
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long _lTruckReplace(SATvm *pstSavm, void *pvAddr, TABLE t, void *pvUpdate)
{
long lRet = RC_SUCC;
SHTruck *pstTruck = NULL;
void *pvData = NULL, *pvCond;
size_t lRow, lOffset = lGetTblData(t);
RWLock *prwLock = (RWLock *)pGetRWLock(pvAddr);
if(NULL == (pvData = (void *)malloc(lGetRowSize(t))))
{
pstSavm->m_lErrno = MALLC_MEM_ERR;
return RC_FAIL;
}
if(RC_SUCC != pthread_rwlock_wrlock(prwLock))
{
pstSavm->m_lErrno = LOCK_DOWR_ERR;
TFree(pvData);
return RC_FAIL;
}
pstSavm->m_lEffect = 0;
pvCond = pstSavm->pstVoid;
pstSavm->m_lEType = EXE_PLAN_ALL;
pstTruck = (PSHTruck)pGetNode(pvAddr, lOffset);
for(lRow = 0; (lRow < ((TblDef *)pvAddr)->m_lValid) && (lOffset < lGetTableSize(t));
pstTruck = (PSHTruck)pGetNode(pvAddr, lOffset))
{
if(IS_TRUCK_NULL(pstTruck))
{
lOffset += lGetRowTruck(t);
continue;
}
lRow ++;
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pvCond))
{
lOffset += lGetRowTruck(t);
continue;
}
memcpy(pvData, pstTruck->m_pvData, lGetRowSize(t));
if(RC_FAIL == lMergeTruck(pstSavm, &pstSavm->stUpdt, pvUpdate, pvData))
goto REPLACE_ERROR;
pstSavm->m_lEffect ++;
pstSavm->pstVoid = pvData;
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NULL);
if(HAVE_UNIQ_IDX(t))
{
if(RC_SUCC != __lIndexUpdate(pstSavm, pvAddr, t, pstTruck, lOffset))
{
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
goto REPLACE_ERROR;
}
}
if(HAVE_NORL_IDX(t))
lRet = __lUpdateGroup(pstSavm, pvAddr, t, pstTruck, lOffset);
else if(HAVE_HASH_IDX(t))
lRet = __lUpdateHash(pstSavm, pvAddr, t, pstTruck, lOffset);
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NRML);
if(RC_SUCC != lRet)
goto REPLACE_ERROR;
if(RC_SUCC != lRecordWork(pstSavm, pstTruck->m_pvData, OPERATE_UPDATE))
goto REPLACE_ERROR;
memcpy(pstTruck->m_pvData, pvData, lGetRowSize(t));
if(FIRST_ROW & pstSavm->lFind) break;
lOffset += lGetRowTruck(t);
}
if(0 == pstSavm->m_lEffect)
{
// If don't find it, so insert
pstSavm->pstVoid = pvUpdate;
lRet = __lInsert(pstSavm, pvAddr, t, 0);
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return lRet;
}
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_SUCC;
REPLACE_ERROR:
pthread_rwlock_unlock(prwLock);
TFree(pvData);
return RC_FAIL;
}
/*************************************************************************************************
descriptionAPI - lReplace
parameters:
pstSavm --stvm handle
pvReplace --replace data
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lReplace(SATvm *pstSavm, void *pvReplace)
{
long lRet;
void *pvData;
RunTime *pstRun = NULL;
if(!pstSavm || !pstSavm->pstVoid)
{
pstSavm->m_lErrno = CONDIT_IS_NIL;
return RC_FAIL;
}
pvData = pstSavm->pstVoid;
if(NULL == (pstRun = (RunTime *)pInitMemTable(pstSavm, pstSavm->tblName)))
return RC_FAIL;
if(RES_REMOT_SID == pstRun->m_lLocal)
{
Tremohold(pstSavm, pstRun);
return RC_FAIL;
// return _lReplaceByRt(pstSavm, psvOut);
}
if(HAVE_UNIQ_IDX(pstSavm->tblName))
{
lRet = _lReplaceIndex(pstSavm, pstRun->m_pvAddr, pstSavm->tblName, pvReplace);
if(RC_CONTU != lRet)
{
vTblDisconnect(pstSavm, pstSavm->tblName);
pstSavm->pstVoid = pvData;
return lRet;
}
}
if(HAVE_NORL_IDX(pstSavm->tblName))
{
lRet = _lReplaceGroup(pstSavm, pstRun->m_pvAddr, pstSavm->tblName, pvReplace);
if(RC_CONTU != lRet)
{
vTblDisconnect(pstSavm, pstSavm->tblName);
pstSavm->pstVoid = pvData;
return lRet;
}
}
else if(HAVE_HASH_IDX(pstSavm->tblName))
{
lRet = _lReplaceHash(pstSavm, pstRun->m_pvAddr, pstSavm->tblName, pvReplace);
if(RC_CONTU != lRet)
{
vTblDisconnect(pstSavm, pstSavm->tblName);
pstSavm->pstVoid = pvData;
return lRet;
}
}
lRet = _lTruckReplace(pstSavm, pstRun->m_pvAddr, pstSavm->tblName, pvReplace);
vTblDisconnect(pstSavm, pstSavm->tblName);
pstSavm->pstVoid = pvData;
return lRet;
}
/*************************************************************************************************
descriptiondump the table data
parameters:
@ -10031,7 +10653,7 @@ long lDumpTable(SATvm *pstSavm, TABLE t)
char szFile[512];
RunTime *pstRun = NULL;
SHTruck *pstTruck = NULL;
long lRow = 0, lOffset;
size_t lRow = 0, lOffset;
if(!pstSavm)
{