add function and fix bugs

pull/1/head
deffpuzzl 2018-05-15 14:33:38 +08:00
parent 5c3b628914
commit e94d8617d9
11 changed files with 614 additions and 310 deletions

View File

@ -1,5 +1,30 @@
# STVM 高效缓存数据库 # STVM 高效缓存数据库
STVMtruck of Virtual memory table是一个开源的使用ANSI C语言编写、支持本地API调用和网络调用全表数据基于IPC共享内存方式存储基于C语言struck结构定义记录行RB-Tree和hash作为主要算法的内存数据库是一款介于SQL和NOSQL之间的一款高速缓存数据库。
* 支持SQL基础语法(insert、update、delete、select、group order、countfirst)功能。
* 支持序列
* 支持唯一索引、查询索引和组合索引
* 支持多字动态查询
* 内置记录点击量(热点数据)
* 集群、主-子同步。
* 事务功能(假性事务)
* 基于IPC进程异常退出不会导致数据丢失除非系统宕机。
* 支持网络API同步、异步和本地API直接调用
* 内置数据版本,维护数据一致安全
* 数据导入、导出接口
***使用须知***
* 表空间大小在创建时已经确定, 一旦创建不能随意修改大小。
* 多机集群无法使用事务。
* 数据无法持久化(宕机情况)。
* 索引长度限制默认64字节修改需编译项目。
* 启动后不能修改表字段
建议使用场景:***数据库缓存、数据缓存***
不定时更新 https://my.oschina.net/deffpuzzl/blog/1627626
## 1、编译 ## 1、编译
**编译项目** **编译项目**
@ -15,32 +40,39 @@ cd src目录 **./make**
* detvm * detvm
## 2、启动 ## 2、启动
新建stvm工作目录 新建stvm工作目录 **mkdir tvmdb**
**mkdir tvmdb** * **TVMDBD=/home/stvm/tvmdb** 指向stvm工作目录
* TVMDBD=/home/stvm/tvmdb 指向stvm工作目录 * **TVMCFG=$(TVMDBD)/.tvm.run** 启动参数
* TVMCFG=/home/stvm/tvmdb/.tvm.run 启动参数
使用方法: 使用方法:
如果不使用多机集群,无需配置域文件,直接 stvm -w 缺省启动单机模式 如果不使用多机集群,无需配置域文件,缺省本地启动。
stvm -s 停止系统 启动系统
> stvm -w [^1]
STVM也提供一个类型sqlpuls类型简单工具 输入: 停止系统
stvm SQL 进入SQL界面该工具主要用来运维调试使用。 > stvm -s
stvm DOM 进入域的维护
STVM也提供一个类型sqlpuls类型简单工具。
进入SQL界面, 该工具主要用来运维调试使用
> stvm SQL
域的维护
> stvm DOM
关于域的配置,请参见: 关于域的配置,请参见:
stvm.conf > vi stvm.conf
配置域完成后,可以配置编译到$TVMCFG下
> stvm -c stvm.conf
配置域完成后可以stvm -c stvm.conf编译到$TVMCFG下
然后在stvm -w启动即可 然后在stvm -w启动即可
目前本版本为测试版本,建议以单机模式64位下运行将性能发挥在极致。 建议以单机模式64位下运行将性能发挥在极致。
**作者:Savens Liu** **作者Savens Liu**
**邮箱:deffpuzzl@qq.com** **邮箱deffpuzzl@qq.com**
## 3、更新 ## 3、更新
====***更新日期:20180312***==== ====***更新日期:20180312***====
@ -65,6 +97,12 @@ stvm DOM 进入域的维护
>* 1、修复create脚本sizeof算法问题。 >* 1、修复create脚本sizeof算法问题。
>* 2、新增异步操作(网络插入、删除、更新)异步接口支持。 >* 2、新增异步操作(网络插入、删除、更新)异步接口支持。
====***更新日期:20180515***====
>* 1、新增脚本msql来批量执行M-SQL语句。
>* 2、对表字段新增别名暂用一些场景字段映射。
>* 3、新增comment关键字在创建脚本文件或M-SQL中本地使用
>* 4、修复char字符拷贝和M-SQL界面非人性化操作。
**下本版本:** **下本版本:**
* 1、新增多机资源共享方式。 * 1、新增多机资源共享方式。
@ -73,3 +111,15 @@ stvm DOM 进入域的维护
**不定时更新** **不定时更新**
[^1]: 常见错误集合 ↑↑
---
#### *常见错误集合* ####
```
Q、failed to boot TVM, Invalid parameter or sem has disappeared
Aecho "500 X X X" > /proc/sys/kernel/sem
```

View File

@ -53,13 +53,13 @@ typedef struct __SOCK_CONNECT
int m_lCltPort; int m_lCltPort;
BSock m_skSock; BSock m_skSock;
int m_isListen; int m_isListen;
void *pvData; void *pvData;
void *pstFace; void *pstFace;
void *pstVoid; void *pstVoid;
int m_lBuffer; int m_lBuffer;
BOOL m_bHead; bool m_bHead;
int m_lRead; int m_lRead;
BOOL m_bWork; bool m_bWork;
ulong m_uWorker; ulong m_uWorker;
CMList *m_pstWork; CMList *m_pstWork;
}SKCon; }SKCon;

View File

@ -60,6 +60,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <stdbool.h>
#include <libgen.h> #include <libgen.h>
typedef short int sint; typedef short int sint;
@ -73,37 +74,9 @@ typedef long int Benum;
typedef unsigned int Uenum; typedef unsigned int Uenum;
typedef int BSock; typedef int BSock;
#ifndef BOOL
typedef unsigned int BOOL;
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef __cplusplus
#ifndef bool
typedef unsigned char bool;
#endif
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#endif // __cplusplus
#define RC_NOTFOUND 24 #define RC_NOTFOUND 24
#define RC_MATCH 2 #define RC_MATCH 2
#define RC_MISMA 1 #define RC_MISMA 1
#define RC_SUCC 0 #define RC_SUCC 0
#define RC_FAIL -1 #define RC_FAIL -1
#define RC_CONTU -5 #define RC_CONTU -5
@ -143,8 +116,6 @@ extern "C" {
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a)) #define MIN(a, b) ((a) > (b) ? (b) : (a))
#define bool(x) (x == 0 ? false : true)
#define BOOL(x) (x == 0 ? false : true)
extern CMList* pGetCMTail(CMList *pstRoot); extern CMList* pGetCMTail(CMList *pstRoot);
extern CMList* pSearchNode(CMList *pstRoot, void *psvData, long lSize); extern CMList* pSearchNode(CMList *pstRoot, void *psvData, long lSize);

View File

@ -288,6 +288,7 @@ typedef long CREATE;
#define UPDFD_NOT_SET 93 // update field not set #define UPDFD_NOT_SET 93 // update field not set
#define EXTRE_SET_ERR 94 // extreme set decorate error #define EXTRE_SET_ERR 94 // extreme set decorate error
#define GROUP_SET_ERR 95 // group set decorate error #define GROUP_SET_ERR 95 // group set decorate error
#define CMM_TABLE_MIS 96 // the table of field is missing
/************************************************************************************************* /*************************************************************************************************
@ -346,21 +347,23 @@ typedef long CREATE;
p->pstVoid = NULL; \ p->pstVoid = NULL; \
}while(0); }while(0);
#define stringsetv(p,s,f,...) vSetCodField(&p->stCond, sizeof((s).f), (void *)(s).f - (void *)&(s)); \ #define stringsetv(p,s,f,...) vSetCodField(&p->stCond, sizeof((s).f), (char *)(s).f - (char *)&(s)); \
snprintf((s).f, sizeof((s).f), __VA_ARGS__); snprintf((s).f, sizeof((s).f), __VA_ARGS__);
#define stringset(p,s,f,v) vSetCodField(&p->stCond, sizeof((s).f), (void *)(s).f - (void *)&(s)); \ #define stringset(p,s,f,v) vSetCodField(&p->stCond, sizeof((s).f), (char *)(s).f - (char *)&(s)); \
strncpy((s).f, v, sizeof((s).f)); strncpy((s).f, v, sizeof((s).f));
#define stringcpy(p,s,f,v) vSetCodField(&p->stCond, sizeof((s).f), (void *)(s).f - (void *)&(s)); \ #define stringcpy(p,s,f,v) vSetCodField(&p->stCond, sizeof((s).f), (char *)(s).f - (char *)&(s)); \
memcpy(&(s) + ((void *)(s).f - (void *)&(s)), (void *)v, sizeof((s).f)); memcpy(&(s) + ((void *)(s).f - (void *)&(s)), (void *)v, sizeof((s).f));
#define numberset(p,s,f,v) vSetCodField(&p->stCond, sizeof((s).f), (void *)&(s).f - (void *)&(s)); \ #define numberset(p,s,f,v) vSetCodField(&p->stCond, sizeof((s).f), (char *)&(s).f - (char *)&(s)); \
(s).f = v; (s).f = v;
#define decorate(p,d,f,v) vSetDecorate(&p->stUpdt, FLEN(d, f), FPOS(d, f), v); \ #define decorate(p,d,f,v) vSetDecorate(&p->stUpdt, FLEN(d, f), FPOS(d, f), v); \
p->lFind = (v) & FIRST_ROW; p->lFind = (v) & FIRST_ROW;
#define conditset(p,s,f) vSetCodField(&p->stCond, sizeof((s).f), (char *)&(s).f - (char *)&(s));
#define stringreset(s,f,v) strncpy((s).f, v, sizeof((s).f)); #define stringreset(s,f,v) strncpy((s).f, v, sizeof((s).f));
#define stringresetv(s,f,...) snprintf((s).f, sizeof((s).f), __VA_ARGS__); #define stringresetv(s,f,...) snprintf((s).f, sizeof((s).f), __VA_ARGS__);
#define stringrecpy(s,f,v) memcpy((s).f, v, sizeof((s).f)); #define stringrecpy(s,f,v) memcpy((s).f, v, sizeof((s).f));
@ -369,15 +372,17 @@ typedef long CREATE;
// UPDATE Field assignment // UPDATE Field assignment
#define updateinit(s) memset(&(s), 0, sizeof(s)); #define updateinit(s) memset(&(s), 0, sizeof(s));
#define stringupd(p,s,f,v) vSetCodField(&p->stUpdt, sizeof((s).f), (void *)(s).f - (void *)&(s)); \ #define stringupd(p,s,f,v) vSetCodField(&p->stUpdt, sizeof((s).f), (char *)(s).f - (char *)&(s)); \
strncpy((s).f, v, sizeof((s).f)); strncpy((s).f, v, sizeof((s).f));
#define stringupy(p,s,f,v) vSetCodField(&p->stUpdt, sizeof((s).f), (void *)(s).f - (void *)&(s)); \ #define stringupy(p,s,f,v) vSetCodField(&p->stUpdt, sizeof((s).f), (char *)(s).f - (char *)&(s)); \
memcpy(&(s) + ((void *)(s).f - (void *)&(s)), (void *)v, sizeof((s).f)); memcpy(&(s) + ((void *)(s).f - (void *)&(s)), (void *)v, sizeof((s).f));
#define numberupd(p,s,f,v) vSetCodField(&p->stUpdt, sizeof((s).f), (void *)&(s).f - (void *)&(s)); \ #define numberupd(p,s,f,v) vSetCodField(&p->stUpdt, sizeof((s).f), (char *)&(s).f - (char *)&(s)); \
(s).f = v; (s).f = v;
#define updateset(p,s,f) vSetCodField(&p->stUpdt, sizeof((s).f), (char *)&(s).f - (char *)&(s));
/************************************************************************************************* /*************************************************************************************************
Table structure & index definition area Table structure & index definition area
*************************************************************************************************/ *************************************************************************************************/
@ -416,6 +421,7 @@ typedef struct __TBL_COM_KEY
long m_lAttr; long m_lAttr;
long m_lIsPk; long m_lIsPk;
char m_szField[MAX_FIELD_LEN]; char m_szField[MAX_FIELD_LEN];
char m_szAlias[MAX_FIELD_LEN];
}TblKey; }TblKey;
typedef struct __TBL_HEAD_DEF typedef struct __TBL_HEAD_DEF
@ -643,6 +649,7 @@ extern TblKey* pGetTblGrp(TABLE t);
extern TblKey* pGetTblKey(TABLE t); extern TblKey* pGetTblKey(TABLE t);
extern RWLock* pGetRWLock(char* pvAddr); extern RWLock* pGetRWLock(char* pvAddr);
extern void vRedeError(long err, char *s); extern void vRedeError(long err, char *s);
extern char* sGetTableName(TABLE t);
extern void* pGetAddr(SATvm *pstSavm, TABLE t); extern void* pGetAddr(SATvm *pstSavm, TABLE t);
extern RunTime* pGetRunTime(SATvm *pstSavm, TABLE t); extern RunTime* pGetRunTime(SATvm *pstSavm, TABLE t);
extern void* pGetNode(void *pvData, size_t lOfs); extern void* pGetNode(void *pvData, size_t lOfs);
@ -701,6 +708,7 @@ extern void* pInitSATvm(TABLE t);
extern long lInitSvCache(SATvm *pstSavm); extern long lInitSvCache(SATvm *pstSavm);
extern void vInitSATvm(SATvm *pstSavm); extern void vInitSATvm(SATvm *pstSavm);
extern bool bTableIsExist(TABLE t); extern bool bTableIsExist(TABLE t);
extern long lAttchTable(SATvm *pstSovm, TABLE t);
extern bool bPartIsExist(char *pszTable, char *pszPart); extern bool bPartIsExist(char *pszTable, char *pszPart);
extern long lInitSATvm(SATvm *pstSavm, TABLE t); extern long lInitSATvm(SATvm *pstSavm, TABLE t);
extern void* pPartSatvm(SATvm *pstSavm, char *pszTable, char *pszPart); extern void* pPartSatvm(SATvm *pstSavm, char *pszTable, char *pszPart);

View File

@ -443,7 +443,7 @@ long _lParseFile(SATvm *pstSavm, CMList **ppstRoot, char *pszFile, const char
{ {
FILE *fp = NULL; FILE *fp = NULL;
char szLine[4098]; char szLine[4098];
BOOL bFlag = FALSE; bool bFlag = false;
CMList *pstList = NULL; CMList *pstList = NULL;
if(NULL == (fp = fopen(pszFile, "rb"))) if(NULL == (fp = fopen(pszFile, "rb")))
@ -467,7 +467,7 @@ long _lParseFile(SATvm *pstSavm, CMList **ppstRoot, char *pszFile, const char
if(!strcmp(pszTarget, szLine) && !bFlag) if(!strcmp(pszTarget, szLine) && !bFlag)
{ {
bFlag = TRUE; bFlag = true;
memset(szLine, 0, sizeof(szLine)); memset(szLine, 0, sizeof(szLine));
continue; continue;
} }
@ -1046,7 +1046,7 @@ PREMOTE_ERROR:
true --repeat true --repeat
false false
*************************************************************************************************/ *************************************************************************************************/
BOOL bDomIsRepeat(long lCount, TDomain *pstDomain) bool bDomIsRepeat(long lCount, TDomain *pstDomain)
{ {
int i, j; int i, j;
@ -1181,7 +1181,7 @@ long lUnmakeConfig(char *pszFile)
char ch; char ch;
TBoot stBoot; TBoot stBoot;
FILE *fp = NULL; FILE *fp = NULL;
BOOL bf = false; bool bf = false;
TIndex *pstIndex = NULL; TIndex *pstIndex = NULL;
TDomain *pstDomain = NULL; TDomain *pstDomain = NULL;
long i, j, lOut = 0, lCount = 0; long i, j, lOut = 0, lCount = 0;

View File

@ -76,7 +76,7 @@ void vDebugTree(void *pvData, SHTree *pstTree)
void vDebugTable(TABLE t, long eType) void vDebugTable(TABLE t, long eType)
{ {
long i = 0, j = 0; long i = 0, j = 0;
RunTime *pstRun = NULL; RunTime *pstRun = NULL;
TblKey *pstKey = NULL; TblKey *pstKey = NULL;
SHTree *pstTree = NULL; SHTree *pstTree = NULL;
SHList *pstList = NULL; SHList *pstList = NULL;
@ -99,49 +99,55 @@ void vDebugTable(TABLE t, long eType)
if(eType & DEBUG_HEAD_INFO) if(eType & DEBUG_HEAD_INFO)
{ {
fprintf(stdout, "\n==========================================TABLE HEAND INFO=============" fprintf(stdout, "\n---------------------------- TABLE HEAND INFO ----------------------"
"============================\n"); "----------\n");
fprintf(stdout, "TABLE:%d, NAME:%s\tSHTree(%ld),SHList(%ld),TblDef(%ld)\n" fprintf(stdout, "TABLE:%9d, extern:%10ld, NAME:%s\t\nSHTree:%8ld, SHList:%10ld, "
"extern:%ld, Group:%ld, MaxRow:%ld, Valid:%ld, lNodeNil:%ld, lIType:%d, " "TblDef:%11ld\nGroup:%9ld, MaxRow:%10ld, Valid:%12ld\nlNodeNil:%6ld, lIType:%10d, "
"Table:%ld\nIdxLen:%ld, TreePos:%ld, TreeRoot:%ld, GrpLen:%ld, GroupPos:%ld, " "Table:%12ld\nIdxLen:%8ld, TreePos:%9ld, TreeRoot:%9d\nGrpLen:%8ld, GroupPos:%8ld, "
"GroupRoot:%ld\nListPos:%ld, ListOfs:%ld, Data:%ld, ReSize:%ld, Truck:%ld\n", "GroupRoot:%8ld\nData:%10ld, ReSize:%10ld, Truck:%12ld\nListPos:%7ld, ListOfs:%9ld\n",
((TblDef *)pGetTblDef(t))->m_table, ((TblDef *)pGetTblDef(t))->m_szTable, ((TblDef *)pGetTblDef(t))->m_table, ((TblDef *)pGetTblDef(t))->m_lExtern,
sizeof(SHTree), sizeof(SHList), sizeof(TblDef), ((TblDef *)pGetTblDef(t))->m_lExtern, ((TblDef *)pGetTblDef(t))->m_szTable, sizeof(SHTree), sizeof(SHList), sizeof(TblDef),
((TblDef *)pGetTblDef(t))->m_lGroup, ((TblDef *)pGetTblDef(t))->m_lMaxRow, ((TblDef *)pGetTblDef(t))->m_lGroup, ((TblDef *)pGetTblDef(t))->m_lMaxRow,
((TblDef *)pGetTblDef(t))->m_lValid, ((TblDef *)pGetTblDef(t))->m_lNodeNil, ((TblDef *)pGetTblDef(t))->m_lValid, ((TblDef *)pGetTblDef(t))->m_lNodeNil,
((TblDef *)pGetTblDef(t))->m_lIType, ((TblDef *)pGetTblDef(t))->m_lIType, ((TblDef *)pGetTblDef(t))->m_lTable,
((TblDef *)pGetTblDef(t))->m_lTable, ((TblDef *)pGetTblDef(t))->m_lIdxLen, ((TblDef *)pGetTblDef(t))->m_lIdxLen, ((TblDef *)pGetTblDef(t))->m_lTreePos,
((TblDef *)pGetTblDef(t))->m_lTreePos, ((TblDef *)pGetTblDef(t))->m_lTreeRoot, ((TblDef *)pGetTblDef(t))->m_lTreeRoot, ((TblDef *)pGetTblDef(t))->m_lGrpLen,
((TblDef *)pGetTblDef(t))->m_lGrpLen, ((TblDef *)pGetTblDef(t))->m_lGroupPos, ((TblDef *)pGetTblDef(t))->m_lGroupPos, ((TblDef *)pGetTblDef(t))->m_lGroupRoot,
((TblDef *)pGetTblDef(t))->m_lGroupRoot, ((TblDef *)pGetTblDef(t))->m_lListPos, ((TblDef *)pGetTblDef(t))->m_lData, ((TblDef *)pGetTblDef(t))->m_lReSize,
((TblDef *)pGetTblDef(t))->m_lListOfs, ((TblDef *)pGetTblDef(t))->m_lData, ((TblDef *)pGetTblDef(t))->m_lTruck, ((TblDef *)pGetTblDef(t))->m_lListPos,
((TblDef *)pGetTblDef(t))->m_lReSize, ((TblDef *)pGetTblDef(t))->m_lTruck); ((TblDef *)pGetTblDef(t))->m_lListOfs);
fprintf(stdout, "--------------------------------------------------------------------"
"----------\n");
pstTree = &((TblDef *)pGetTblDef(t))->m_stNil; pstTree = &((TblDef *)pGetTblDef(t))->m_stNil;
fprintf(stdout, ">>NODE_NULL POS:[%8ld], Idx:[%s](%ld)(%ld), Color[%ld], lSePos:[%4ld], lParent[%4ld]" fprintf(stdout, ">>NIL:[%8ld], Idx:[%s](%ld)(%ld), Color[%ld], lSePos:[%4ld], lParent[%4ld]"
", left[%4ld], right[%4ld]\n" , (void *)pstTree - (void *)pGetTblDef(t), pstTree->m_szIdx, ", left[%4ld], right[%4ld]\n" , (void *)pstTree - (void *)pGetTblDef(t), pstTree->m_szIdx,
pstTree->m_lIdx, pstTree->m_lData, pstTree->m_eColor, pstTree->m_lSePos, pstTree->m_lParent, pstTree->m_lIdx, pstTree->m_lData, pstTree->m_eColor, pstTree->m_lSePos, pstTree->m_lParent,
pstTree->m_lLeft, pstTree->m_lRight); pstTree->m_lLeft, pstTree->m_lRight);
fprintf(stdout, "==========UNIQ INDEX FIELD=========\n"); fprintf(stdout, "\n--------------------------------UNIQ INDEX FIELD--------------"
"----------------\n");
for(i = 0, pstKey = pGetTblIdx(t); i < lGetIdxNum(t); i ++) for(i = 0, pstKey = pGetTblIdx(t); i < lGetIdxNum(t); i ++)
{ {
fprintf(stdout, "From:%4ld, len:%3ld, attr:%ld, IsPk:%ld, field:%s\n", pstKey[i].m_lFrom, fprintf(stdout, "From:%4ld, len:%3ld, attr:%ld, IsPk:%ld, field:%s\n", pstKey[i].m_lFrom,
pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk, pstKey[i].m_szField); pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk, pstKey[i].m_szField);
} }
fprintf(stdout, "==========GROUP INDEX FIELD========\n"); fprintf(stdout, "\n--------------------------------UNIQ INDEX FIELD--------------"
"----------------\n");
for(i = 0, pstKey = pGetTblGrp(t); i < lGetGrpNum(t); i ++) for(i = 0, pstKey = pGetTblGrp(t); i < lGetGrpNum(t); i ++)
{ {
fprintf(stdout, "From:%4ld, len:%3ld, attr:%ld, IsPk:%ld, field:%s\n", pstKey[i].m_lFrom, fprintf(stdout, "From:%4ld, len:%3ld, attr:%ld, IsPk:%ld, field:%s\n", pstKey[i].m_lFrom,
pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk, pstKey[i].m_szField); pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk, pstKey[i].m_szField);
} }
fprintf(stdout, "==================== TABLE FIELD ====================\n"); fprintf(stdout, "\n_______________________________ TABLE FIELD ____________________"
"_____________\n");
for(i = 0, pstKey = pGetTblKey(t); i < lGetFldNum(t); i ++) for(i = 0, pstKey = pGetTblKey(t); i < lGetFldNum(t); i ++)
{ {
fprintf(stdout, "From:%4ld, len:%3ld, attr:%ld, IsPk:%ld, field:%s\n", pstKey[i].m_lFrom, fprintf(stdout, "pos:%4ld, len:%3ld, atr:%ld, pk:%ld, fld:%-20s, als:%s\n",
pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk, pstKey[i].m_szField); pstKey[i].m_lFrom, pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk,
pstKey[i].m_szField, pstKey[i].m_szAlias);
} }
} }
@ -262,8 +268,8 @@ void vDebugTable(TABLE t, long eType)
} }
vTblDisconnect(pstSavm, pstSavm->tblName); vTblDisconnect(pstSavm, pstSavm->tblName);
fprintf(stdout, "==========================================================================" fprintf(stdout, "================================================================="
"===================================\n"); "==============\n");
} }
/************************************************************************************************* /*************************************************************************************************
@ -271,7 +277,7 @@ void vDebugTable(TABLE t, long eType)
parameters: parameters:
return: return:
*************************************************************************************************/ *************************************************************************************************/
void vGetAction(char *s, long *plAction) void vGetAction(char *s, int *plAction)
{ {
int i, nLen; int i, nLen;
@ -318,43 +324,12 @@ void vGetAction(char *s, long *plAction)
*************************************************************************************************/ *************************************************************************************************/
void vPrintFunc(char *s) void vPrintFunc(char *s)
{ {
fprintf(stdout, "\nUsage:\t%s -[tpr][hugldtui]\n", s); fprintf(stdout, "\nUsage:\t%s -[t][hugldtui]\n", s);
fprintf(stdout, "\t-t\t\t--table\n"); fprintf(stdout, "\t-t\t\t--table\n");
fprintf(stdout, "\t-p[hugldta]\t--debug\n"); fprintf(stdout, "\t-p[hugldta]\t--debug\n");
fprintf(stdout, "\t-r\t\t--reset lock\n");
fprintf(stdout, "\n"); fprintf(stdout, "\n");
} }
/*************************************************************************************************
descriptiondebug action
parameters:
return:
*************************************************************************************************/
void vDebugAction(TABLE t, int iAction, char *pszApp, char *pszParam)
{
long lRet, lDebug = 0;
SATvm *pstSavm = (SATvm *)pGetSATvm();
if(3 == iAction)
{
if(RC_SUCC != lResetLock((SATvm *)pGetSATvm(), t))
{
fprintf(stderr, "reset the table lock (%d) failed, err:(%d)(%s)\n", t,
pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return ;
}
}
else if(5 == iAction)
{
vGetAction(pszParam, &lDebug);
vDebugTable(t, lDebug);
}
else
vPrintFunc(pszApp);
return ;
}
/************************************************************************************************* /*************************************************************************************************
descriptionmain descriptionmain
parameters: parameters:
@ -367,7 +342,7 @@ int main(int argc, char *argv[])
int iChoose = 0, iAction = 0; int iChoose = 0, iAction = 0;
memset(szCom, 0, sizeof(szCom)); memset(szCom, 0, sizeof(szCom));
while(-1 != (iChoose = getopt(argc, argv, "t:p:r::v?::"))) while(-1 != (iChoose = getopt(argc, argv, "t:p::v?::")))
{ {
switch(iChoose) switch(iChoose)
{ {
@ -375,12 +350,12 @@ int main(int argc, char *argv[])
iAction |= 1; iAction |= 1;
t = atol(optarg); t = atol(optarg);
break; break;
case 'r':
iAction |= 2;
break;
case 'p': case 'p':
iAction |= 4; iAction |= 4;
strcpy(szCom, optarg); if(!optarg)
szCom[0] = 'h';
else
strcpy(szCom, optarg);
break; break;
case 'v': case 'v':
case '?': case '?':
@ -390,7 +365,15 @@ int main(int argc, char *argv[])
} }
} }
vDebugAction(t, iAction, basename(argv[0]), szCom); iChoose = 0;
if(5 == iAction)
{
vGetAction(szCom, &iChoose);
vDebugTable(t, iChoose);
return RC_SUCC;
}
vPrintFunc(basename(argv[0]));
return RC_SUCC; return RC_SUCC;
} }

View File

@ -754,15 +754,15 @@ long lSortRowgrp(Rowgrp **root, FdCond *pstExm, TABLE t)
pstCond --field list pstCond --field list
uNice --next index of field uNice --next index of field
return: return:
TRUE --success true --success
FALSE --failure false --failure
*************************************************************************************************/ *************************************************************************************************/
bool bCompare(void *s, void *p, FdCond *pstCond, uint uNice) bool bCompare(void *s, void *p, FdCond *pstCond, uint uNice)
{ {
FdKey *pstKey; FdKey *pstKey;
if(pstCond->uFldcmp <= uNice) if(pstCond->uFldcmp <= uNice)
return TRUE; return true;
pstKey = &pstCond->stFdKey[uNice]; pstKey = &pstCond->stFdKey[uNice];
if(pstKey->uDecorate & ORDER_ASC) if(pstKey->uDecorate & ORDER_ASC)
@ -774,20 +774,20 @@ bool bCompare(void *s, void *p, FdCond *pstCond, uint uNice)
{ {
case 4: case 4:
if(*((float *)(s + pstKey->uFldpos)) > *((float *)(p + pstKey->uFldpos))) if(*((float *)(s + pstKey->uFldpos)) > *((float *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((float *)(s + pstKey->uFldpos)) == *((float *)(p + pstKey->uFldpos))) else if(*((float *)(s + pstKey->uFldpos)) == *((float *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
case 8: case 8:
if(*((double *)(s + pstKey->uFldpos)) > *((double *)(p + pstKey->uFldpos))) if(*((double *)(s + pstKey->uFldpos)) > *((double *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((float *)(s + pstKey->uFldpos)) == *((float *)(p + pstKey->uFldpos))) else if(*((float *)(s + pstKey->uFldpos)) == *((float *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
default: default:
return FALSE; return false;
} }
break; break;
case FIELD_LONG: case FIELD_LONG:
@ -795,36 +795,36 @@ bool bCompare(void *s, void *p, FdCond *pstCond, uint uNice)
{ {
case 2: case 2:
if(*((sint *)(s + pstKey->uFldpos)) > *((sint *)(p + pstKey->uFldpos))) if(*((sint *)(s + pstKey->uFldpos)) > *((sint *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((sint *)(s + pstKey->uFldpos)) == *((sint *)(p + pstKey->uFldpos))) else if(*((sint *)(s + pstKey->uFldpos)) == *((sint *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
case 4: case 4:
if(*((int *)(s + pstKey->uFldpos)) > *((int *)(p + pstKey->uFldpos))) if(*((int *)(s + pstKey->uFldpos)) > *((int *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((int *)(s + pstKey->uFldpos)) == *((int *)(p + pstKey->uFldpos))) else if(*((int *)(s + pstKey->uFldpos)) == *((int *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
case 8: case 8:
if(*((llong *)(s + pstKey->uFldpos)) > *((llong *)(p + pstKey->uFldpos))) if(*((llong *)(s + pstKey->uFldpos)) > *((llong *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((llong *)(s + pstKey->uFldpos)) == *((llong *)(p + pstKey->uFldpos))) else if(*((llong *)(s + pstKey->uFldpos)) == *((llong *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
default: default:
return FALSE; return false;
} }
break; break;
case FIELD_CHAR: case FIELD_CHAR:
if(0 < memcmp(s + pstKey->uFldpos, p + pstKey->uFldpos, pstKey->uFldlen)) if(0 < memcmp(s + pstKey->uFldpos, p + pstKey->uFldpos, pstKey->uFldlen))
return TRUE; return true;
else if(0 == memcmp(s + pstKey->uFldpos, p + pstKey->uFldpos, pstKey->uFldlen)) else if(0 == memcmp(s + pstKey->uFldpos, p + pstKey->uFldpos, pstKey->uFldlen))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
break; break;
default: default:
break; break;
@ -839,20 +839,20 @@ bool bCompare(void *s, void *p, FdCond *pstCond, uint uNice)
{ {
case 4: case 4:
if(*((float *)(s + pstKey->uFldpos)) < *((float *)(p + pstKey->uFldpos))) if(*((float *)(s + pstKey->uFldpos)) < *((float *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((float *)(s + pstKey->uFldpos)) == *((float *)(p + pstKey->uFldpos))) else if(*((float *)(s + pstKey->uFldpos)) == *((float *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
case 8: case 8:
if(*((double *)(s + pstKey->uFldpos)) < *((double *)(p + pstKey->uFldpos))) if(*((double *)(s + pstKey->uFldpos)) < *((double *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((float *)(s + pstKey->uFldpos)) == *((float *)(p + pstKey->uFldpos))) else if(*((float *)(s + pstKey->uFldpos)) == *((float *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
default: default:
return FALSE; return false;
} }
break; break;
case FIELD_LONG: case FIELD_LONG:
@ -860,36 +860,36 @@ bool bCompare(void *s, void *p, FdCond *pstCond, uint uNice)
{ {
case 2: case 2:
if(*((sint *)(s + pstKey->uFldpos)) < *((sint *)(p + pstKey->uFldpos))) if(*((sint *)(s + pstKey->uFldpos)) < *((sint *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((sint *)(s + pstKey->uFldpos)) == *((sint *)(p + pstKey->uFldpos))) else if(*((sint *)(s + pstKey->uFldpos)) == *((sint *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
case 4: case 4:
if(*((int *)(s + pstKey->uFldpos)) < *((int *)(p + pstKey->uFldpos))) if(*((int *)(s + pstKey->uFldpos)) < *((int *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((int *)(s + pstKey->uFldpos)) == *((int *)(p + pstKey->uFldpos))) else if(*((int *)(s + pstKey->uFldpos)) == *((int *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
case 8: case 8:
if(*((llong *)(s + pstKey->uFldpos)) < *((llong *)(p + pstKey->uFldpos))) if(*((llong *)(s + pstKey->uFldpos)) < *((llong *)(p + pstKey->uFldpos)))
return TRUE; return true;
else if(*((llong *)(s + pstKey->uFldpos)) == *((llong *)(p + pstKey->uFldpos))) else if(*((llong *)(s + pstKey->uFldpos)) == *((llong *)(p + pstKey->uFldpos)))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
default: default:
return FALSE; return false;
} }
break; break;
case FIELD_CHAR: case FIELD_CHAR:
if(0 > memcmp(s + pstKey->uFldpos, p + pstKey->uFldpos, pstKey->uFldlen)) if(0 > memcmp(s + pstKey->uFldpos, p + pstKey->uFldpos, pstKey->uFldlen))
return TRUE; return true;
else if(0 == memcmp(s + pstKey->uFldpos, p + pstKey->uFldpos, pstKey->uFldlen)) else if(0 == memcmp(s + pstKey->uFldpos, p + pstKey->uFldpos, pstKey->uFldlen))
return bCompare(s, p, pstCond, ++ uNice); return bCompare(s, p, pstCond, ++ uNice);
else else
return FALSE; return false;
break; break;
default: default:
break; break;

View File

@ -181,7 +181,7 @@ char* strimall(char *p)
char* strimfield(char *s) char* strimfield(char *s)
{ {
register int i, n, m; register int i, n, m;
BOOL bf = false; bool bf = false;
if(!s || 0 == (n = strlen(s))) if(!s || 0 == (n = strlen(s)))
return s; return s;
@ -212,7 +212,7 @@ char* strimfield(char *s)
long lfieldnum(char *p, char *k) long lfieldnum(char *p, char *k)
{ {
char *y = p; char *y = p;
BOOL bf = false; bool bf = false;
long idx, i, m, n; long idx, i, m, n;
if(!p || !k) return 0; if(!p || !k) return 0;
@ -280,7 +280,7 @@ int bIsgbk(const char *s)
char* sfieldvalue(char *p, char *k, int id) char* sfieldvalue(char *p, char *k, int id)
{ {
char *y = p; char *y = p;
BOOL bf = false; bool bf = false;
long idx, i = 0, m = 0, n = 0; long idx, i = 0, m = 0, n = 0;
static char szOut[1024]; static char szOut[1024];

View File

@ -38,6 +38,7 @@ extern char **environ;
extern long lShutdownTvm(); extern long lShutdownTvm();
extern void vSetNode(char *s); extern void vSetNode(char *s);
extern long lStartupTvm(TBoot *pstBoot); extern long lStartupTvm(TBoot *pstBoot);
extern long lMountTable(SATvm *pstSavm, char *pszFile);
/************************************************************************************************* /*************************************************************************************************
descriptionget stvm version descriptionget stvm version
@ -119,6 +120,46 @@ void vSCRDebug(const char *fmt, ...)
fprintf(stdout, "%s\n", szMsg); fprintf(stdout, "%s\n", szMsg);
} }
/*************************************************************************************************
descriptionReturns the current time in millisecond
parameters
return
lTime --millisecond
*************************************************************************************************/
long lGetTiskTime()
{
long lTime;
struct timeval t;
struct tm *ptm;
gettimeofday(&t, NULL);
ptm = localtime(&t.tv_sec);
lTime = ptm->tm_min * 60 * 1000 + ptm->tm_sec * 1000 + t.tv_usec / 1000;
return lTime;
}
/*************************************************************************************************
descriptionCalculate time consumption (milliseconds)
parameters
return
szTime --Time string
*************************************************************************************************/
char* sGetCostTime(long lTime)
{
static char szTime[30];
memset(szTime, 0, sizeof(szTime));
if(lTime < 0)
snprintf(szTime, sizeof(szTime), "cost:nan");
if(lTime < 1000)
snprintf(szTime, sizeof(szTime), "cost:%ldms", lTime);
else
snprintf(szTime, sizeof(szTime), "cost:%lds%ldms", lTime / 1000, lTime % 1000);
return szTime;
}
/************************************************************************************************* /*************************************************************************************************
descriptionget pragma pack descriptionget pragma pack
parameters parameters
@ -197,7 +238,7 @@ int sizecn(TblKey *pstKey, long lfld)
for(i = 0, k = 0; i < lfld; i ++) for(i = 0, k = 0; i < lfld; i ++)
{ {
pv = &pstKey[i]; pv = &pstKey[i];
if(FIELD_CHAR == pv->m_lAttr) if(FIELD_CHAR == pv->m_lAttr && 0 == k)
{ {
k = sizeof(char); k = sizeof(char);
continue; continue;
@ -219,7 +260,7 @@ int sizecn(TblKey *pstKey, long lfld)
if(FIELD_CHAR != pv->m_lAttr) if(FIELD_CHAR != pv->m_lAttr)
{ {
/* 数据对齐原则----内存按结构成员的先后顺序排列,当排到该成员变量时, /* 数据对齐原则----内存按结构成员的先后顺序排列,当排到该成员变量时,
* */ * */
/* 没有考虑用户指定 指定对齐值:#pragma pack (value)时指定的对齐value。 */ /* 没有考虑用户指定 指定对齐值:#pragma pack (value)时指定的对齐value。 */
if(pack > pv->m_lLen) if(pack > pv->m_lLen)
n = pv->m_lLen; n = pv->m_lLen;
@ -314,6 +355,81 @@ long lAnalysHead(char *s, long len, TblDef *pstTde)
return RC_SUCC; return RC_SUCC;
} }
/*************************************************************************************************
descriptionalias table field name
parameters
pstTde --Table define
pszField --string
pszAlias --string
return
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lTableAliase(TblDef *pstTde, char *pszField, char *pszAlias)
{
long i = 0;
TblKey *pv = NULL;
for(i = 0; i < pstTde->m_lIdxNum; i ++)
{
pv = &pstTde->m_stKey[i];
if(strcmp(pv->m_szField, pszField))
continue;
memset(pv->m_szAlias, 0, sizeof(pv->m_szAlias));
strncpy(pv->m_szAlias, pszAlias, sizeof(pv->m_szAlias));
return RC_SUCC;
}
return RC_FAIL;
}
/*************************************************************************************************
descriptionalias the table field name
parameters
pstTde --Table define
pszField --string
pszAlias --string
return
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long _lParseAlias(SATvm *pstSavm, char *pszTable, char *pszField, char *pszAlias)
{
TIndex stIndex;
RunTime *pstRun = NULL;
long lTime = lGetTiskTime();
memset(&stIndex, 0, sizeof(TIndex));
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(RC_SUCC != lGetTblIndex(pstSavm, stIndex.m_szTable, stIndex.m_szPart, &stIndex))
return RC_FAIL;
if(RC_SUCC != lInitSATvm(pGetSATvm(), stIndex.m_table))
return RC_FAIL;
if(NULL == (pstRun = (RunTime *)pInitHitTest(pstSavm, stIndex.m_table)))
return RC_FAIL;
if(RC_SUCC != lTableAliase((TblDef *)pstRun->m_pvAddr, pszField, pszAlias))
{
pstSavm->m_lErrno = FIL_NOT_EXIST;
vTblDisconnect(pstSavm, stIndex.m_table);
return RC_FAIL;
}
vTblDisconnect(pstSavm, stIndex.m_table);
lTime -= lGetTiskTime();
fprintf(stdout, "---(1) comment updated, %s---\n", sGetCostTime(-1 * lTime));
return RC_SUCC;
}
/************************************************************************************************* /*************************************************************************************************
descriptionanalysis of the table descriptionanalysis of the table
parameters parameters
@ -352,6 +468,7 @@ long lAnalysTable(char *s, long len, TblDef *pstTde)
pv = &pstTde->m_stKey[pstTde->m_lIdxNum]; pv = &pstTde->m_stKey[pstTde->m_lIdxNum];
strncpy(pv->m_szField, sfieldvalue(szTemp, " ", 1), MAX_FIELD_LEN); strncpy(pv->m_szField, sfieldvalue(szTemp, " ", 1), MAX_FIELD_LEN);
strcpy(pv->m_szAlias, pv->m_szField);
if(!strlen(pv->m_szField)) if(!strlen(pv->m_szField))
{ {
fprintf(stderr, "field define error\n"); fprintf(stderr, "field define error\n");
@ -389,7 +506,12 @@ long lAnalysTable(char *s, long len, TblDef *pstTde)
pv->m_lAttr = FIELD_DOUB; pv->m_lAttr = FIELD_DOUB;
pv->m_lLen = sizeof(float); pv->m_lLen = sizeof(float);
} }
else if(!strncasecmp(szTar, "char", 1)) else if(!strcasecmp(szTar, "byte"))
{
pv->m_lAttr = FIELD_CHAR;
pv->m_lLen = sizeof(char);
}
else if(!strncasecmp(szTar, "char", 4))
{ {
pv->m_lAttr = FIELD_CHAR; pv->m_lAttr = FIELD_CHAR;
if(!strcasecmp(szTar, "char")) if(!strcasecmp(szTar, "char"))
@ -409,7 +531,7 @@ long lAnalysTable(char *s, long len, TblDef *pstTde)
} }
else else
{ {
fprintf(stderr, "Undefined field type\n"); fprintf(stderr, "Undefined field type: %s", szTar);
return RC_FAIL; return RC_FAIL;
} }
@ -521,8 +643,12 @@ long lAnalysIndex(char *s, long len, TblDef *pstTde)
{ {
long i, n, k, lRet; long i, n, k, lRet;
char szIndex[1024], szTemp[256], *p = NULL; char szIndex[1024], szTemp[256], *p = NULL;
char szComm[512], szAlias[64], szTable[256];
memset(szComm, 0, sizeof(szComm));
memset(szIndex, 0, sizeof(szIndex)); memset(szIndex, 0, sizeof(szIndex));
memset(szAlias, 0, sizeof(szAlias));
memset(szTable, 0, sizeof(szTable));
if(len > sizeof(szIndex) || len < 1) if(len > sizeof(szIndex) || len < 1)
{ {
fprintf(stderr, "table head define error\n"); fprintf(stderr, "table head define error\n");
@ -578,15 +704,73 @@ long lAnalysIndex(char *s, long len, TblDef *pstTde)
k |= NORMAL; k |= NORMAL;
lRet = lIndexField(p, pstTde, HASHID); lRet = lIndexField(p, pstTde, HASHID);
} }
else if(p = strcasestr(szTemp, "comment on "))
{
// comment on table.column_name is 'comments';
p = p + 11;
strncpy(szComm, sfieldvalue(p, " ", 1), sizeof(szComm));
if(strcasestr(szComm, "column"))
{
p += 7;
strncpy(szComm, sfieldvalue(p, " ", 1), sizeof(szComm));
}
p += strlen(szComm) + 1;
if(!strcasestr(p, "is "))
{
fprintf(stderr, "comment syntax define error\n");
return RC_FAIL;
}
p += 3;
memset(szAlias, 0, sizeof(szAlias));
memset(szTable, 0, sizeof(szTable));
strncpy(szAlias, p, sizeof(szAlias));
DEL_TAIL_CHAR(szAlias, ';');
strimabout(szAlias, "'", "'");
strimabout(szAlias, "\"", "\"");
if(strstr(szComm, "."))
{
strncpy(szTable, sfieldvalue(szComm, ".", 1), sizeof(szTable));
p = szComm + strlen(szTable) + 1;
strimabout(p, "'", "'");
strimabout(p, "\"", "\"");
if(!strcmp(szTable, pstTde->m_szTable)) // current table
{
if(RC_SUCC != (lRet = lTableAliase(pstTde, p, szAlias)))
{
fprintf(stderr, "table %s field:%s not exist\n", szTable, p);
return RC_FAIL;
}
}
else
{
if(RC_SUCC != (lRet = _lParseAlias((SATvm *)pGetSATvm(), szTable, p, szAlias)))
{
fprintf(stderr, "comment %s field %s failure, %s\n", szTable, p,
sGetTError(lGetTErrno()));
return RC_FAIL;
}
}
}
else
{
if(RC_SUCC != (lRet = lTableAliase(pstTde, szComm, szAlias)))
{
fprintf(stderr, "table %s field:%s not exist\n", szTable, szComm);
return RC_FAIL;
}
}
}
else else
{ {
fprintf(stderr, "index define error\n"); fprintf(stderr, "%s, syntax define error\n", szTemp);
return RC_FAIL; return RC_FAIL;
} }
if(RC_SUCC != lRet) if(RC_SUCC != lRet)
{ {
fprintf(stderr, "parse index field error\n"); fprintf(stderr, "parse create syntax error\n");
return RC_FAIL; return RC_FAIL;
} }
} }
@ -651,13 +835,18 @@ void vCreateStruck(TblDef *pstTde, bool bf)
{ {
pv = &pstTde->m_stKey[i]; pv = &pstTde->m_stKey[i];
if(FIELD_CHAR == pv->m_lAttr) if(FIELD_CHAR == pv->m_lAttr)
fprintf(stdout, " char %s[%ld];\n", pv->m_szField, pv->m_lLen); {
if(1 == pv->m_lLen)
fprintf(stdout, " char %s;\n", pv->m_szField);
else
fprintf(stdout, " char %s[%ld];\n", pv->m_szField, pv->m_lLen);
}
else if(FIELD_LONG == pv->m_lAttr) else if(FIELD_LONG == pv->m_lAttr)
{ {
switch(pv->m_lLen) switch(pv->m_lLen)
{ {
case 2: case 2:
fprintf(stdout, " short %s;\n", pv->m_szField); fprintf(stdout, " short %s;\n", pv->m_szField);
break; break;
case 4: case 4:
fprintf(stdout, " int %s;\n", pv->m_szField); fprintf(stdout, " int %s;\n", pv->m_szField);
@ -790,6 +979,7 @@ long lDefineTable(char *pszCreate, char *pszTable)
strncpy(stTde.m_szTable, sfieldvalue(p + 12, "\n", 1), sizeof(stTde.m_szTable)); strncpy(stTde.m_szTable, sfieldvalue(p + 12, "\n", 1), sizeof(stTde.m_szTable));
srtrim(stTde.m_szTable); srtrim(stTde.m_szTable);
sltrim(stTde.m_szTable); sltrim(stTde.m_szTable);
supper(stTde.m_szTable);
if(NULL == (q = strcasestr(p, ";"))) if(NULL == (q = strcasestr(p, ";")))
{ {
@ -985,46 +1175,6 @@ SQLFld* pSortSQLField(SQLFld *pstRoot)
return pstRoot; return pstRoot;
} }
/*************************************************************************************************
descriptionReturns the current time in millisecond
parameters
return
lTime --millisecond
*************************************************************************************************/
long lGetTiskTime()
{
long lTime;
struct timeval t;
struct tm *ptm;
gettimeofday(&t, NULL);
ptm = localtime(&t.tv_sec);
lTime = ptm->tm_min * 60 * 1000 + ptm->tm_sec * 1000 + t.tv_usec / 1000;
return lTime;
}
/*************************************************************************************************
descriptionCalculate time consumption (milliseconds)
parameters
return
szTime --Time string
*************************************************************************************************/
char* sGetCostTime(long lTime)
{
static char szTime[30];
memset(szTime, 0, sizeof(szTime));
if(lTime < 0)
return szTime;
if(lTime < 1000)
snprintf(szTime, sizeof(szTime), "cost:%ldms", lTime);
else
snprintf(szTime, sizeof(szTime), "cost:%lds%ldms", lTime / 1000, lTime % 1000);
return szTime;
}
/************************************************************************************************* /*************************************************************************************************
descriptionPrinting system index descriptionPrinting system index
parameters parameters
@ -1580,7 +1730,15 @@ long _lUpdateField(SATvm *pstSavm, char *pszField, long lCount, TField *pstFi
memcpy(pvUpdate + pfld->m_lFrom, v, pfld->m_lLen); memcpy(pvUpdate + pfld->m_lFrom, v, pfld->m_lLen);
break; break;
case FIELD_CHAR: case FIELD_CHAR:
strncpy(pvUpdate + pfld->m_lFrom, szValue, pfld->m_lLen); switch(pfld->m_lLen)
{
case 1:
memcpy(pvUpdate + pfld->m_lFrom, szValue, pfld->m_lLen);
break;
default:
strncpy(pvUpdate + pfld->m_lFrom, szValue, pfld->m_lLen);
break;
}
break; break;
default: default:
return RC_FAIL; return RC_FAIL;
@ -1597,9 +1755,9 @@ long _lUpdateField(SATvm *pstSavm, char *pszField, long lCount, TField *pstFi
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lExeUpdate(SATvm *pstSavm, TIndex *pstIndex, void *pvNew, char *pvData, BOOL bRmt) long _lExeUpdate(SATvm *pstSavm, TIndex *pstIndex, void *pvNew, char *pvData, bool bRmt)
{ {
long lRet; long lRet, lTime = lGetTiskTime();
pstSavm->pstVoid = (void *)pvData; pstSavm->pstVoid = (void *)pvData;
pstSavm->tblName = pstIndex->m_table; pstSavm->tblName = pstIndex->m_table;
@ -1614,8 +1772,10 @@ long _lExeUpdate(SATvm *pstSavm, TIndex *pstIndex, void *pvNew, char *pvData,
sGetTError(pstSavm->m_lErrno)); sGetTError(pstSavm->m_lErrno));
return RC_FAIL; return RC_FAIL;
} }
lTime -= lGetTiskTime();
fprintf(stdout, "---(%ld) records updated -ep(%d)--\n", pstSavm->m_lEffect, pstSavm->m_lEType); fprintf(stdout, "---(%ld) records updated, ep(%d), %s---\n", pstSavm->m_lEffect, pstSavm->m_lEType,
sGetCostTime(-1 * lTime));
return RC_SUCC; return RC_SUCC;
} }
@ -1626,9 +1786,9 @@ long _lExeUpdate(SATvm *pstSavm, TIndex *pstIndex, void *pvNew, char *pvData,
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lExeDelete(SATvm *pstSavm, TIndex *pstIndex, char *pvData, BOOL bRmt) long _lExeDelete(SATvm *pstSavm, TIndex *pstIndex, char *pvData, bool bRmt)
{ {
long lRet; long lRet, lTime = lGetTiskTime();
pstSavm->pstVoid = (void *)pvData; pstSavm->pstVoid = (void *)pvData;
pstSavm->tblName = pstIndex->m_table; pstSavm->tblName = pstIndex->m_table;
@ -1639,8 +1799,10 @@ long _lExeDelete(SATvm *pstSavm, TIndex *pstIndex, char *pvData, BOOL bRmt)
lRet = lDelete(pstSavm); lRet = lDelete(pstSavm);
if(RC_SUCC != lRet) if(RC_SUCC != lRet)
return RC_FAIL; return RC_FAIL;
lTime -= lGetTiskTime();
fprintf(stdout, "---(%ld) records deleted -ep(%d)--\n", pstSavm->m_lEffect, pstSavm->m_lEType); fprintf(stdout, "---(%ld) records deleted, ep(%d), %s---\n", pstSavm->m_lEffect, pstSavm->m_lEType,
sGetCostTime(-1 * lTime));
return RC_SUCC; return RC_SUCC;
} }
@ -1651,9 +1813,9 @@ long _lExeDelete(SATvm *pstSavm, TIndex *pstIndex, char *pvData, BOOL bRmt)
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lExeInsert(SATvm *pstSavm, TIndex *pstIndex, void *pvInsert, BOOL bRmt) long _lExeInsert(SATvm *pstSavm, TIndex *pstIndex, void *pvInsert, bool bRmt)
{ {
long lRet; long lRet, lTime = lGetTiskTime();
if(bRmt) if(bRmt)
pstSavm->tblName = pstIndex->m_table; pstSavm->tblName = pstIndex->m_table;
@ -1675,8 +1837,9 @@ long _lExeInsert(SATvm *pstSavm, TIndex *pstIndex, void *pvInsert, BOOL bRmt)
sGetTError(pstSavm->m_lErrno)); sGetTError(pstSavm->m_lErrno));
return RC_FAIL; return RC_FAIL;
} }
lTime -= lGetTiskTime();
fprintf(stdout, "---(%ld) records inserted ---\n", pstSavm->m_lEffect); fprintf(stdout, "---(%ld) records inserted, %s---\n", pstSavm->m_lEffect, sGetCostTime(-1 * lTime));
return RC_SUCC; return RC_SUCC;
} }
@ -1758,7 +1921,15 @@ long _lConditField(SATvm *pstSavm, char *pszWhere, long lCount, TField *pstFi
memcpy(pvWhere + pfld->m_lFrom, v, pfld->m_lLen); memcpy(pvWhere + pfld->m_lFrom, v, pfld->m_lLen);
break; break;
case FIELD_CHAR: case FIELD_CHAR:
strncpy(pvWhere + pfld->m_lFrom, szValue, pfld->m_lLen); switch(pfld->m_lLen)
{
case 1:
memcpy(pvWhere + pfld->m_lFrom, szValue, pfld->m_lLen);
break;
default:
strncpy(pvWhere + pfld->m_lFrom, szValue, pfld->m_lLen);
break;
}
break; break;
default: default:
return RC_FAIL; return RC_FAIL;
@ -1775,9 +1946,10 @@ long _lConditField(SATvm *pstSavm, char *pszWhere, long lCount, TField *pstFi
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lCountSelect(SATvm *pstSavm, TIndex *pstIndex, char *pvData, BOOL bRmt) long _lCountSelect(SATvm *pstSavm, TIndex *pstIndex, char *pvData, bool bRmt)
{ {
size_t lRet, lSum = 0; size_t lRet, lSum = 0;
long lTime = lGetTiskTime();
pstSavm->pstVoid = (void *)pvData; pstSavm->pstVoid = (void *)pvData;
pstSavm->tblName = pstIndex->m_table; pstSavm->tblName = pstIndex->m_table;
@ -1792,11 +1964,13 @@ long _lCountSelect(SATvm *pstSavm, TIndex *pstIndex, char *pvData, BOOL bRmt)
sGetTError(pstSavm->m_lErrno)); sGetTError(pstSavm->m_lErrno));
return RC_FAIL; return RC_FAIL;
} }
lTime -= lGetTiskTime();
fprintf(stdout, "---(%ld) records selected -ep(%d)--\n", pstSavm->m_lEffect, pstSavm->m_lEType);
fprintf(stdout, "COUNT(*)\n"); fprintf(stdout, "COUNT(*)\n");
fprintf(stdout, "%zu\n", lSum); fprintf(stdout, "%zu\n", lSum);
fflush(stdout); fflush(stdout);
fprintf(stdout, "---(%ld) records selected, ep(%d), %s---\n", pstSavm->m_lEffect,
pstSavm->m_lEType, sGetCostTime(-1 * lTime));
return RC_SUCC; return RC_SUCC;
} }
@ -1808,12 +1982,13 @@ long _lCountSelect(SATvm *pstSavm, TIndex *pstIndex, char *pvData, BOOL bRmt)
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lExeGroup(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvData, BOOL bRmt) long _lExeGroup(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvData, bool bRmt)
{ {
TblKey *pstKey = NULL; TblKey *pstKey = NULL;
SQLFld *pstNode = NULL; SQLFld *pstNode = NULL;
Rowgrp *pstList = NULL; Rowgrp *pstList = NULL;
char *pvResult = NULL; char *pvResult = NULL;
long lTime = lGetTiskTime();
size_t i, lOffset, lRows, lRet; size_t i, lOffset, lRows, lRet;
pstSavm->pstVoid = (void *)pvData; pstSavm->pstVoid = (void *)pvData;
@ -1891,8 +2066,10 @@ long _lExeGroup(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvDa
fflush(stdout); fflush(stdout);
} }
TFree(pvResult); TFree(pvResult);
lTime -= lGetTiskTime();
fprintf(stdout, "---(%ld) records selected, ep(%d)---\n", pstSavm->m_lEffect, pstSavm->m_lEType); fprintf(stdout, "---(%ld) records selected, ep(%d), %s---\n", pstSavm->m_lEffect,
pstSavm->m_lEType, sGetCostTime(-1 * lTime));
return RC_SUCC; return RC_SUCC;
} }
@ -1904,12 +2081,13 @@ long _lExeGroup(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvDa
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lExeSelect(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvData, char *pszFile, long _lExeSelect(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvData, char *pszFile,
char *pszDem, BOOL bRmt) char *pszDem, bool bRmt)
{ {
FILE *fp = NULL; FILE *fp = NULL;
TblKey *pstKey = NULL; TblKey *pstKey = NULL;
SQLFld *pstNode = NULL; SQLFld *pstNode = NULL;
Rowgrp *pstList = NULL; Rowgrp *pstList = NULL;
long lTime = lGetTiskTime();
size_t i, lOffset, lRows, lRet; size_t i, lOffset, lRows, lRet;
char szDelmit[64], *pvResult = NULL; char szDelmit[64], *pvResult = NULL;
@ -2004,14 +2182,18 @@ long _lExeSelect(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvD
fflush(fp); fflush(fp);
} }
TFree(pvResult); TFree(pvResult);
lTime -= lGetTiskTime();
if(pszFile) if(pszFile)
{ {
fprintf(stdout, "---(%ld) records unload ---\n", pstSavm->m_lEffect); fprintf(stdout, "---(%ld) records unload, %s---\n", pstSavm->m_lEffect, sGetCostTime(-1 * lTime));
fclose(fp); fclose(fp);
} }
else else
fprintf(stdout, "---(%ld) records selected, ep(%d)---\n", pstSavm->m_lEffect, pstSavm->m_lEType); {
fprintf(stdout, "---(%ld) records selected, ep(%d), %s---\n", pstSavm->m_lEffect,
pstSavm->m_lEType, sGetCostTime(-1 * lTime));
}
return RC_SUCC; return RC_SUCC;
} }
@ -2023,7 +2205,7 @@ long _lExeSelect(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, char *pvD
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long lParseSequece(SATvm *pstSavm, char *pszSQName, char *pszFiled, BOOL bRmt) long lParseSequece(SATvm *pstSavm, char *pszSQName, char *pszFiled, bool bRmt)
{ {
long lRet; long lRet;
ulong ulSeque; ulong ulSeque;
@ -2165,12 +2347,12 @@ long lParseAdorn(SATvm *pstSavm, char *pszAdorn, long lCount, TField *pstFiel
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lExeExtreme(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, void *pvData, BOOL bRmt) long _lExeExtreme(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, void *pvData, bool bRmt)
{ {
long lRet;
TblKey *pstKey = NULL; TblKey *pstKey = NULL;
SQLFld *pstNode = NULL; SQLFld *pstNode = NULL;
void *pvResult = NULL; void *pvResult = NULL;
long lRet, lTime = lGetTiskTime();
if(NULL == (pvResult = malloc(pstIndex->m_lRowSize))) if(NULL == (pvResult = malloc(pstIndex->m_lRowSize)))
return RC_FAIL; return RC_FAIL;
@ -2233,11 +2415,13 @@ long _lExeExtreme(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, void *pv
break; break;
} }
} }
lTime -= lGetTiskTime();
fprintf(stdout, "\n"); fprintf(stdout, "\n");
fflush(stdout); fflush(stdout);
TFree(pvResult); TFree(pvResult);
fprintf(stdout, "---(%ld)records selected -ep(%d)--\n", pstSavm->m_lEffect, pstSavm->m_lEType); fprintf(stdout, "---(%ld) records selected, ep(%d), %s--\n", pstSavm->m_lEffect, pstSavm->m_lEType,
sGetCostTime(-1 * lTime));
return RC_SUCC; return RC_SUCC;
} }
@ -2250,7 +2434,7 @@ long _lExeExtreme(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, void *pv
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lParseSelect(SATvm *pstSavm, char *pszTable, char *pszField, char *pszWhere, char *pszFile, long _lParseSelect(SATvm *pstSavm, char *pszTable, char *pszField, char *pszWhere, char *pszFile,
char *pszDem, char *pszAdorn, BOOL bRmt) char *pszDem, char *pszAdorn, bool bRmt)
{ {
TIndex stIndex; TIndex stIndex;
SQLFld *pstRoot = NULL; SQLFld *pstRoot = NULL;
@ -2370,7 +2554,7 @@ ERR_SELECT:
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
**************************************************************************************************/ **************************************************************************************************/
long _lSelectSyntax(SATvm *pstSavm, char *pszSQL, char *pszFile, char *pszDem, BOOL bRmt) long _lSelectSyntax(SATvm *pstSavm, char *pszSQL, char *pszFile, char *pszDem, bool bRmt)
{ {
char szTable[512], *p = NULL; char szTable[512], *p = NULL;
char szWhere[512], szField[512], szAdorn[1024]; char szWhere[512], szField[512], szAdorn[1024];
@ -2452,7 +2636,7 @@ long _lSelectSyntax(SATvm *pstSavm, char *pszSQL, char *pszFile, char *pszDem
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lParseUpdate(SATvm *pstSavm, char *pszTable, char *pszField, char *pszWhere, BOOL bRmt) long _lParseUpdate(SATvm *pstSavm, char *pszTable, char *pszField, char *pszWhere, bool bRmt)
{ {
TIndex stIndex; TIndex stIndex;
size_t lOut = 0, lRet; size_t lOut = 0, lRet;
@ -2535,7 +2719,7 @@ ERR_UPDATE:
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
**************************************************************************************************/ **************************************************************************************************/
long _lUpdateSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt) long _lUpdateSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
{ {
char szTable[MAX_FIELD_LEN]; char szTable[MAX_FIELD_LEN];
char szWhere[1024], szField[1024]; char szWhere[1024], szField[1024];
@ -2596,7 +2780,7 @@ long _lUpdateSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt)
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lParseDelete(SATvm *pstSavm, char *pszTable, char *pszWhere, BOOL bRmt) long _lParseDelete(SATvm *pstSavm, char *pszTable, char *pszWhere, bool bRmt)
{ {
TIndex stIndex; TIndex stIndex;
size_t lOut = 0, lRet; size_t lOut = 0, lRet;
@ -2664,7 +2848,7 @@ ERR_DELETE:
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
**************************************************************************************************/ **************************************************************************************************/
long _lDeleteSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt) long _lDeleteSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
{ {
char szTable[MAX_FIELD_LEN], szWhere[1024]; char szTable[MAX_FIELD_LEN], szWhere[1024];
@ -2706,6 +2890,57 @@ long _lDeleteSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt)
return _lParseDelete(pstSavm, szTable, szWhere, bRmt); return _lParseDelete(pstSavm, szTable, szWhere, bRmt);
} }
/**************************************************************************************************
descriptionParse SQL-delete syntax
parameters
return
RC_SUCC --success
RC_FAIL --failure
**************************************************************************************************/
long _lCommentSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
{
char szTable[MAX_FIELD_LEN], szAlias[128], szCom[512], *pszField = NULL;
memset(szCom, 0, sizeof(szCom));
memset(szTable, 0, sizeof(szTable));
memset(szAlias, 0, sizeof(szAlias));
if(!sGetTruckValue(pszSQL, "on ", " is ", true, szCom, sizeof(szCom)))
{
pstSavm->m_lErrno = SQL_SYNTX_ERR;
return RC_FAIL;
}
strimall(szCom);
if(!sGetTruckValue(pszSQL, " is ", NULL, true, szAlias, sizeof(szAlias)))
{
pstSavm->m_lErrno = SQL_SYNTX_ERR;
return RC_FAIL;
}
strimall(szAlias);
DEL_TAIL_CHAR(szAlias, ';');
strimabout(szAlias, "'", "'");
strimabout(szAlias, "\"", "\"");
if(!strstr(szCom, "."))
{
pstSavm->m_lErrno = CMM_TABLE_MIS;
return RC_FAIL;
}
strncpy(szTable, sfieldvalue(szCom, ".", 1), sizeof(szTable));
pszField = szCom + strlen(szTable) + 1;
strimabout(pszField, "'", "'");
strimabout(pszField, "\"", "\"");
if(RC_SUCC != _lParseAlias(pstSavm, szTable, pszField, szAlias))
{
fprintf(stderr, "comment %s field %s failure, %s\n", szTable,
pszField, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
return RC_SUCC;
}
/************************************************************************************************* /*************************************************************************************************
descriptionParse SQL-insert values descriptionParse SQL-insert values
parameters parameters
@ -2805,7 +3040,7 @@ long _lInsertField(SATvm *pstSavm, char *pszValues, SQLFld *pstRoot, void *pv
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lParseInsert(SATvm *pstSavm, char *pszTable, char *pszField, char *pszValues, BOOL bRmt) long _lParseInsert(SATvm *pstSavm, char *pszTable, char *pszField, char *pszValues, bool bRmt)
{ {
TIndex stIndex; TIndex stIndex;
size_t lOut = 0, lRet; size_t lOut = 0, lRet;
@ -2879,7 +3114,7 @@ ERR_INSERT:
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
**************************************************************************************************/ **************************************************************************************************/
long _lInsertSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt) long _lInsertSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
{ {
char szTable[MAX_FIELD_LEN]; char szTable[MAX_FIELD_LEN];
char szValues[1024], szField[1024]; char szValues[1024], szField[1024];
@ -2957,11 +3192,11 @@ long _lInsertSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt)
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
**************************************************************************************************/ **************************************************************************************************/
long _lTruncateSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt) long _lTruncateSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
{ {
long lRet;
TIndex stIndex; TIndex stIndex;
char szTable[MAX_FIELD_LEN]; char szTable[MAX_FIELD_LEN];
long lRet, lTime = lGetTiskTime();
memset(szTable, 0, sizeof(szTable)); memset(szTable, 0, sizeof(szTable));
memset(&stIndex, 0, sizeof(TIndex)); memset(&stIndex, 0, sizeof(TIndex));
@ -3002,7 +3237,8 @@ long _lTruncateSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt)
if(RC_SUCC != lRet) if(RC_SUCC != lRet)
return RC_FAIL; return RC_FAIL;
fprintf(stdout, "---(%ld) records deleted ---\n", pstSavm->m_lEffect); lTime -= lGetTiskTime();
fprintf(stdout, "---(%ld) records deleted, %s---\n", pstSavm->m_lEffect, sGetCostTime(-1 * lTime));
return RC_SUCC; return RC_SUCC;
} }
@ -3013,7 +3249,7 @@ long _lTruncateSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt)
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
**************************************************************************************************/ **************************************************************************************************/
long _lDropSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt) long _lDropSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
{ {
long lRet; long lRet;
TIndex stIndex; TIndex stIndex;
@ -3073,6 +3309,7 @@ long _lDropSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt)
long _lLoadSyntax(SATvm *pstSavm, char *pszSQL) long _lLoadSyntax(SATvm *pstSavm, char *pszSQL)
{ {
TIndex stIndex; TIndex stIndex;
long lTime = lGetTiskTime();
char szFile[256], szParam[256], szDelmit[64]; char szFile[256], szParam[256], szDelmit[64];
// load from a.txt DELIMITER ',' insert into tablename@bcs // load from a.txt DELIMITER ',' insert into tablename@bcs
@ -3130,7 +3367,9 @@ long _lLoadSyntax(SATvm *pstSavm, char *pszSQL)
if(RC_SUCC != lImportFile(stIndex.m_table, szFile, szDelmit)) if(RC_SUCC != lImportFile(stIndex.m_table, szFile, szDelmit))
return RC_FAIL; return RC_FAIL;
fprintf(stdout, "---(%ld) records inserted ---\n", pstSavm->m_lEffect); lTime -= lGetTiskTime();
fprintf(stdout, "---(%ld) records inserted, %s---\n", pstSavm->m_lEffect,
sGetCostTime(-1 * lTime));
return RC_SUCC; return RC_SUCC;
} }
@ -3142,7 +3381,7 @@ long _lLoadSyntax(SATvm *pstSavm, char *pszSQL)
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
**************************************************************************************************/ **************************************************************************************************/
long _lUnloadSyntax(SATvm *pstSavm, char *pszSQL, BOOL bRmt) long _lUnloadSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
{ {
char szFile[256], szParam[256], szDelmit[64], *p = NULL; char szFile[256], szParam[256], szDelmit[64], *p = NULL;
@ -3206,34 +3445,37 @@ long lExecuteSQL(SATvm *pstSavm, char *pszSQL)
} }
pstSavm->lFind = 0; pstSavm->lFind = 0;
pstSavm->m_lErrno = 0;
pstSavm->stCond.uFldcmp = 0; pstSavm->stCond.uFldcmp = 0;
pstSavm->stUpdt.uFldcmp = 0; pstSavm->stUpdt.uFldcmp = 0;
if(!strncasecmp(pszSQL, "begin ", 6) && strcmp(sfieldvalue(pszSQL, ";", 2), "work")) if(!strcasecmp(pszSQL, "begin work"))
{ {
vBeginWork(pstSavm); vBeginWork(pstSavm);
fprintf(stdout, "---begin work, %s---\n", sGetTError(pstSavm->m_lErrno)); fprintf(stdout, "---begin work, %s---\n", sGetTError(pstSavm->m_lErrno));
return RC_SUCC; return RC_SUCC;
} }
else if(!strncasecmp(pszSQL, "end ", 4) && strcmp(sfieldvalue(pszSQL, ";", 2), "work")) else if(!strcasecmp(pszSQL, "end work"))
{ {
vEndWork(pstSavm); vEndWork(pstSavm);
fprintf(stdout, "---end work, %s---\n", sGetTError(pstSavm->m_lErrno)); fprintf(stdout, "---end work, %s---\n", sGetTError(pstSavm->m_lErrno));
return RC_SUCC; return RC_SUCC;
} }
else if(!strncasecmp(pszSQL, "commit ", 7) && strcmp(sfieldvalue(pszSQL, ";", 2), "work")) else if(!strcasecmp(pszSQL, "commit work"))
{ {
lCommitWork(pstSavm); lCommitWork(pstSavm);
fprintf(stdout, "---commit work, %s---\n", sGetTError(pstSavm->m_lErrno)); fprintf(stdout, "---commit work, %s---\n", sGetTError(pstSavm->m_lErrno));
return RC_SUCC; return RC_SUCC;
} }
else if(!strncasecmp(pszSQL, "rollback ", 9) && strcmp(sfieldvalue(pszSQL, ";", 2), "work")) else if(!strcasecmp(pszSQL, "rollback work"))
{ {
lRollbackWork(pstSavm); lRollbackWork(pstSavm);
fprintf(stdout, "---(%ld) records rollback, %s---\n", pstSavm->m_lEffect, fprintf(stdout, "---(%ld) records rollback, %s---\n", pstSavm->m_lEffect,
sGetTError(pstSavm->m_lErrno)); sGetTError(pstSavm->m_lErrno));
return RC_SUCC; return RC_SUCC;
} }
else if(!strncasecmp(pszSQL, "comment ", 8))
return _lCommentSyntax(pstSavm, pszSQL + 8, false);
else if(!strncasecmp(pszSQL, "select ", 7)) else if(!strncasecmp(pszSQL, "select ", 7))
return _lSelectSyntax(pstSavm, pszSQL, NULL, NULL, false); return _lSelectSyntax(pstSavm, pszSQL, NULL, NULL, false);
else if(!strncasecmp(pszSQL, "update ", 7)) else if(!strncasecmp(pszSQL, "update ", 7))
@ -3276,26 +3518,27 @@ long lExecuteTvm(SATvm *pstSavm, char *pszSQL)
pstSavm->m_lTimes = 0; pstSavm->m_lTimes = 0;
pstSavm->m_lErrno = 0; pstSavm->m_lErrno = 0;
pstSavm->m_lErrno = 0;
sfieldreplace(pszSQL, '\t', ' '); sfieldreplace(pszSQL, '\t', ' ');
if(!strncasecmp(pszSQL, "begin ", 6) && strcmp(sfieldvalue(pszSQL, ";", 2), "work")) if(!strcasecmp(pszSQL, "begin work"))
{ {
lTvmBeginWork(pstSavm); lTvmBeginWork(pstSavm);
fprintf(stdout, "---begin work, %s---\n", sGetTError(pstSavm->m_lErrno)); fprintf(stdout, "---begin work, %s---\n", sGetTError(pstSavm->m_lErrno));
return RC_SUCC; return RC_SUCC;
} }
else if(!strncasecmp(pszSQL, "end ", 4) && strcmp(sfieldvalue(pszSQL, ";", 2), "work")) else if(!strcasecmp(pszSQL, "end work"))
{ {
lTvmEndWork(pstSavm); lTvmEndWork(pstSavm);
fprintf(stdout, "---end work, %s---\n", sGetTError(pstSavm->m_lErrno)); fprintf(stdout, "---end work, %s---\n", sGetTError(pstSavm->m_lErrno));
return RC_SUCC; return RC_SUCC;
} }
else if(!strncasecmp(pszSQL, "commit ", 7) && strcmp(sfieldvalue(pszSQL, ";", 2), "work")) else if(!strcasecmp(pszSQL, "commit work"))
{ {
lTvmCommitWork(pstSavm); lTvmCommitWork(pstSavm);
fprintf(stdout, "---commit work, %s---\n", sGetTError(pstSavm->m_lErrno)); fprintf(stdout, "---commit work, %s---\n", sGetTError(pstSavm->m_lErrno));
return RC_SUCC; return RC_SUCC;
} }
else if(!strncasecmp(pszSQL, "rollback ", 9) && strcmp(sfieldvalue(pszSQL, ";", 2), "work")) else if(!strcasecmp(pszSQL, "rollback work"))
{ {
lTvmRollbackWork(pstSavm); lTvmRollbackWork(pstSavm);
fprintf(stdout, "---(%ld) records rollback, %s---\n", pstSavm->m_lEffect, fprintf(stdout, "---(%ld) records rollback, %s---\n", pstSavm->m_lEffect,
@ -3315,6 +3558,8 @@ long lExecuteTvm(SATvm *pstSavm, char *pszSQL)
else if(!strncasecmp(pszSQL, "drop ", 5)) else if(!strncasecmp(pszSQL, "drop ", 5))
return _lDropSyntax(pstSavm, pszSQL, true); return _lDropSyntax(pstSavm, pszSQL, true);
/* /*
else if(!strncasecmp(pszSQL, "comment ", 8))
return _lCommentSyntax(pstSavm, pszSQL + 8, false);
else if(!strncasecmp(pszSQL, "load ", 5)) else if(!strncasecmp(pszSQL, "load ", 5))
return _lLoadSyntax(pstSavm, pszSQL, true); return _lLoadSyntax(pstSavm, pszSQL, true);
*/ */
@ -3385,7 +3630,7 @@ long lStartSystem(TBoot *pstBoot, char *pszMode)
**************************************************************************************************/ **************************************************************************************************/
long lStopSystem(TBoot *pstBoot, char *pszApp) long lStopSystem(TBoot *pstBoot, char *pszApp)
{ {
BOOL bRet; bool bRet;
long i, lPid = 0; long i, lPid = 0;
FILE *fp = NULL; FILE *fp = NULL;
static char szCmd[128], szPid[20]; static char szCmd[128], szPid[20];
@ -3414,7 +3659,7 @@ long lStopSystem(TBoot *pstBoot, char *pszApp)
for(i = 0; i < 200; i ++, usleep(50000)) for(i = 0; i < 200; i ++, usleep(50000))
{ {
if(FALSE == (bRet = bExistProcess(lPid))) if(false == (bRet = bExistProcess(lPid)))
break; break;
} }
@ -3570,11 +3815,13 @@ void vPrintFunc(char *s)
fprintf(stdout, "\t-s\t\t--Shutdown STVM\n"); fprintf(stdout, "\t-s\t\t--Shutdown STVM\n");
fprintf(stdout, "\t-p(ytd)\t\t--Output STVM Running information\n"); fprintf(stdout, "\t-p(ytd)\t\t--Output STVM Running information\n");
fprintf(stdout, "\t-f\t\t--Display the amount of table\n"); fprintf(stdout, "\t-f\t\t--Display the amount of table\n");
fprintf(stdout, "\t-t\t\t--Output the table struck\n"); fprintf(stdout, "\t-i table\t--Rebuild index on the table\n");
fprintf(stdout, "\t-d\t\t--Dump the table\n"); fprintf(stdout, "\t-l table\t--Reset lock of the table\n");
fprintf(stdout, "\t-m\t\t--Mount the table\n"); fprintf(stdout, "\t-t table\t--Output the table struck\n");
fprintf(stdout, "\t-c[file]\t--Compile the startup config file\n"); fprintf(stdout, "\t-d file\t\t--Dump the table files\n");
fprintf(stdout, "\t-o[file]\t--Decompile the startup config\n"); fprintf(stdout, "\t-m file\t\t--Mount the table files\n");
fprintf(stdout, "\t-c conf\t\t--Compile the startup config file\n");
fprintf(stdout, "\t-o conf\t\t--Decompile the startup config\n");
fprintf(stdout, "\n"); fprintf(stdout, "\n");
fprintf(stdout, "\n"); fprintf(stdout, "\n");
fprintf(stdout, "\033[4m\033[45;33mDESCRIPTION\033[0m\n"); fprintf(stdout, "\033[4m\033[45;33mDESCRIPTION\033[0m\n");
@ -3593,6 +3840,9 @@ void vAddHistory(char *s)
FILE *fp = NULL; FILE *fp = NULL;
char szPath[512]; char szPath[512];
if(!s || !strlen(s))
return ;
memset(szPath, 0, sizeof(szPath)); memset(szPath, 0, sizeof(szPath));
snprintf(szPath, sizeof(szPath), "%s/%s", getenv("TVMDBD"), STVM_SQL_LINE); snprintf(szPath, sizeof(szPath), "%s/%s", getenv("TVMDBD"), STVM_SQL_LINE);
if(NULL == (fp = fopen(szPath, "a+"))) if(NULL == (fp = fopen(szPath, "a+")))
@ -3654,9 +3904,10 @@ void vSetHistory()
**************************************************************************************************/ **************************************************************************************************/
void vSQLStatement(int argc, char *argv[]) void vSQLStatement(int argc, char *argv[])
{ {
char *pszUser, *p, szSQL[2048]; FILE *fp = NULL;
long i = 0, lRec, lRemote = 0, lRet; long i = 0, lRec, lRemote = 0, lRet;
SATvm *pstSavm = (SATvm *)pGetSATvm(); SATvm *pstSavm = (SATvm *)pGetSATvm();
char *pszUser, *p, szSQL[2048], szText[2048];
system("stty erase ^?"); system("stty erase ^?");
system("stty erase ^H"); system("stty erase ^H");
@ -3665,6 +3916,15 @@ void vSQLStatement(int argc, char *argv[])
{ {
if(!strcasecmp(argv[i], "--debug=on")) if(!strcasecmp(argv[i], "--debug=on"))
elog = 1; elog = 1;
else if(!strncasecmp(argv[i], "--msql=", 7))
{
if(NULL == (fp = fopen(argv[i] + 7, "rb")))
{
fprintf(stderr, "open file %s error, %s\n", argv[i] + 7,
strerror(errno));
exit(-1);
}
}
else if(!strncasecmp(argv[i], "--connect=", 10)) else if(!strncasecmp(argv[i], "--connect=", 10))
{ {
if(NULL == (pszUser = strstr(argv[i], "--connect="))) if(NULL == (pszUser = strstr(argv[i], "--connect=")))
@ -3699,14 +3959,27 @@ void vSQLStatement(int argc, char *argv[])
vSetHistory(); vSetHistory();
while(1) while(1)
{ {
if(NULL == (pszUser = readline("M-SQL>"))) if(fp)
continue; {
memset(szText, 0, sizeof(szText));
if(!fgets(szText, sizeof(szText), fp))
{
fclose(fp);
break;
}
strimcrlf(szText);
pszUser = strdup(szText);
}
else
{
if(NULL == (pszUser = readline("M-SQL>")))
continue;
}
if(!strcmp(pszUser, "q") || !strcmp(pszUser, "Q") || !strcmp(pszUser, "exit")) if(!strcmp(pszUser, "q") || !strcmp(pszUser, "Q") || !strcmp(pszUser, "exit"))
break; break;
add_history(pszUser);
vAddHistory(pszUser);
if(!strcasecmp(pszUser, "clear")) if(!strcasecmp(pszUser, "clear"))
{ {
system("clear"); system("clear");
@ -3722,10 +3995,14 @@ void vSQLStatement(int argc, char *argv[])
continue; continue;
} }
memset(szSQL, 0, sizeof(szSQL));
strcpy(szSQL, pszUser);
lCreateByFile(pszUser + 6); lCreateByFile(pszUser + 6);
fprintf(stdout, "\n\n\n"); fprintf(stdout, "\n\n\n");
TFree(pszUser); add_history(szSQL);
continue; vAddHistory(szSQL);
TFree(pszUser);
continue;
} }
strimcrlf(pszUser); strimcrlf(pszUser);
@ -3734,10 +4011,12 @@ void vSQLStatement(int argc, char *argv[])
{ {
memset(szSQL, 0, sizeof(szSQL)); memset(szSQL, 0, sizeof(szSQL));
strncpy(szSQL, sfieldvalue(pszUser, ";", i + 1), sizeof(szSQL)); strncpy(szSQL, sfieldvalue(pszUser, ";", i + 1), sizeof(szSQL));
strimcrlf(szSQL);
sltrim(szSQL); sltrim(szSQL);
srtrim(szSQL); srtrim(szSQL);
if(!strlen(szSQL)) continue; if(!strlen(szSQL)) continue;
add_history(szSQL);
sfieldreplace(szSQL, '\t', ' '); sfieldreplace(szSQL, '\t', ' ');
fprintf(stdout, "\n------------------------------------------------------SQL Result" fprintf(stdout, "\n------------------------------------------------------SQL Result"
"-----------------------------------------------------\n"); "-----------------------------------------------------\n");
@ -3751,6 +4030,8 @@ void vSQLStatement(int argc, char *argv[])
sGetTError(pstSavm->m_lErrno)); sGetTError(pstSavm->m_lErrno));
continue; continue;
} }
vAddHistory(szSQL);
} }
TFree(pszUser); TFree(pszUser);
fprintf(stdout, "\n\n\n"); fprintf(stdout, "\n\n\n");
@ -4054,25 +4335,17 @@ void vCheckTvmEnv()
{ {
int nRet; int nRet;
if(!getenv("TVMCFG"))
{
fprintf(stderr, "Environment variable \"TVMCFG\" is not set\n");
exit(-1);
}
if(!getenv("TVMDBD")) if(!getenv("TVMDBD"))
{ {
fprintf(stderr, "Environment variable \"TVMDBD\" is not set\n"); fprintf(stderr, "Environment variable \"TVMDBD\" is not set\n");
exit(-1); exit(-1);
} }
/* if(!getenv("TVMCFG"))
if(0 != access(getenv("TVMDBD"), F_OK | X_OK ))
{ {
fprintf(stderr, "\"TVMDBD\" directory isnot set yet!\n"); fprintf(stderr, "Environment variable \"TVMCFG\" is not set\n");
exit(-1); exit(-1);
} }
*/
mkdir(getenv("TVMDBD"), S_IRWXU | S_IRWXG | S_IROTH | S_IEXEC ); mkdir(getenv("TVMDBD"), S_IRWXU | S_IRWXG | S_IROTH | S_IEXEC );
} }
@ -4105,7 +4378,7 @@ int main(int argc, char *argv[])
vCheckTvmEnv(); vCheckTvmEnv();
memset(szCom, 0, sizeof(szCom)); memset(szCom, 0, sizeof(szCom));
while(-1 != (iChoose = getopt(argc, argv, "w::s::p::f::d:m:t:i:c:v?::"))) while(-1 != (iChoose = getopt(argc, argv, "w::s::p::f::d:m:t:i:l:c:v?::")))
{ {
switch(iChoose) switch(iChoose)
{ {
@ -4136,6 +4409,16 @@ int main(int argc, char *argv[])
if(RC_SUCC != lRebuildIndex(pstSavm, table)) if(RC_SUCC != lRebuildIndex(pstSavm, table))
fprintf(stderr, "rebuild index failure, %s\n", sGetTError(pstSavm->m_lErrno)); fprintf(stderr, "rebuild index failure, %s\n", sGetTError(pstSavm->m_lErrno));
return RC_SUCC; return RC_SUCC;
case 'l':
fprintf(stdout, "Do you want to initialize the lock of table (%d) 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));
else
fprintf(stderr, "重置表(%d)完成, completed successfully !!\n", atol(optarg));
return RC_SUCC;
case 'v': case 'v':
fprintf(stdout, "%s\n", sGetTVMVers()); fprintf(stdout, "%s\n", sGetTVMVers());
fflush(stdout); fflush(stdout);

View File

@ -335,7 +335,7 @@ long lSetBlock(BSock skSock)
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
BSock skConnectServer(SATvm *pstSavm, char *pszIp, long lPort, BOOL bf, long lTime) BSock skConnectServer(SATvm *pstSavm, char *pszIp, long lPort, bool bf, long lTime)
{ {
fd_set set, exp; fd_set set, exp;
struct timeval tv; struct timeval tv;
@ -356,7 +356,7 @@ BSock skConnectServer(SATvm *pstSavm, char *pszIp, long lPort, BOOL bf, long
} }
memset(&lin, 0, sizeof(lin)); memset(&lin, 0, sizeof(lin));
lin.l_onoff = TRUE; lin.l_onoff = true;
lin.l_linger = 10; lin.l_linger = 10;
if (0 > setsockopt(skSock, SOL_SOCKET, SO_LINGER, &lin, sizeof(lin))) if (0 > setsockopt(skSock, SOL_SOCKET, SO_LINGER, &lin, sizeof(lin)))
{ {
@ -1653,7 +1653,7 @@ long lEpollAccept(SATvm *pstSavm, BSock epfd, SKCon *pc)
} }
pstCon->m_lRead = 0; pstCon->m_lRead = 0;
pstCon->m_bHead = FALSE; pstCon->m_bHead = false;
pstCon->m_skSock = skAccept; pstCon->m_skSock = skAccept;
pstCon->m_lCltPort = ntohs(cAddr.sin_port); pstCon->m_lCltPort = ntohs(cAddr.sin_port);
pstCon->pvData = pstCon->pstFace + sizeof(TFace); pstCon->pvData = pstCon->pstFace + sizeof(TFace);
@ -1729,7 +1729,7 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi
lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace));
vResetRemote(pstSovm, pstCon->m_szCltIp, pstFace->m_lFind, pstCon->m_skSock); vResetRemote(pstSovm, pstCon->m_szCltIp, pstFace->m_lFind, pstCon->m_skSock);
pstCon->m_lRead = 0; pstCon->m_lRead = 0;
pstCon->m_bHead = FALSE; pstCon->m_bHead = false;
return RC_SUCC; return RC_SUCC;
} }
@ -1742,7 +1742,7 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi
return RC_SUCC; return RC_SUCC;
pstCon->m_lRead = 0; pstCon->m_lRead = 0;
pstCon->m_bHead = FALSE; pstCon->m_bHead = false;
pstRun = (RunTime *)pGetRunTime(pstSovm, pstFace->m_table); pstRun = (RunTime *)pGetRunTime(pstSovm, pstFace->m_table);
pstRun->m_bAttch = pstSovm->stRunTime[pstFace->m_table].m_bAttch; pstRun->m_bAttch = pstSovm->stRunTime[pstFace->m_table].m_bAttch;
pstRun->m_pvAddr = pstSovm->stRunTime[pstFace->m_table].m_pvAddr; pstRun->m_pvAddr = pstSovm->stRunTime[pstFace->m_table].m_pvAddr;
@ -1832,7 +1832,7 @@ void* vEpollListen(void *pvParam)
lEpollAccept(pstSavm, epfd, pstCon); lEpollAccept(pstSavm, epfd, pstCon);
else if(events[i].events & EPOLLIN) else if(events[i].events & EPOLLIN)
{ {
if(FALSE == pstCon->m_bHead) if(false == pstCon->m_bHead)
{ {
if(0 > (lRet = lRecvBuffer(pstCon->m_skSock, pstCon->pstFace + pstCon->m_lRead, if(0 > (lRet = lRecvBuffer(pstCon->m_skSock, pstCon->pstFace + pstCon->m_lRead,
sizeof(TFace) - pstCon->m_lRead))) sizeof(TFace) - pstCon->m_lRead)))
@ -1866,7 +1866,7 @@ void* vEpollListen(void *pvParam)
checkrequest(pstSavm, pstCon, pstFace); checkrequest(pstSavm, pstCon, pstFace);
pstCon->m_lRead = 0; pstCon->m_lRead = 0;
pstCon->m_bHead = TRUE; pstCon->m_bHead = true;
} }
if(RC_FAIL == lPollRequest(pstSavm, pstCon, pstFace, pstCon->pstVoid, if(RC_FAIL == lPollRequest(pstSavm, pstCon, pstFace, pstCon->pstVoid,

View File

@ -144,6 +144,7 @@ static char tvmerr[100][MAX_INDEX_LEN] = {
"update field not set", "update field not set",
"extreme set decorate error", "extreme set decorate error",
"group set decorate error", "group set decorate error",
"the table of field is missing",
"", "",
}; };
@ -1061,7 +1062,7 @@ char* sGetTablePart(TABLE t, char *pszNode)
*************************************************************************************************/ *************************************************************************************************/
void vHoldConnect(SATvm *pstSavm) void vHoldConnect(SATvm *pstSavm)
{ {
pstSavm->m_bHold = TRUE; pstSavm->m_bHold = true;
} }
/************************************************************************************************* /*************************************************************************************************
@ -1081,7 +1082,7 @@ void vHoldRelease(SATvm *pstSavm)
return; return;
} }
pstSavm->m_bHold = FALSE; pstSavm->m_bHold = false;
for(t = 0; t < TVM_MAX_TABLE; t ++) for(t = 0; t < TVM_MAX_TABLE; t ++)
{ {
pstRun = (RunTime *)pGetRunTime(pstSavm, t); pstRun = (RunTime *)pGetRunTime(pstSavm, t);
@ -1099,7 +1100,7 @@ void vHoldRelease(SATvm *pstSavm)
if(pstRun->m_pvAddr) if(pstRun->m_pvAddr)
shmdt(pstRun->m_pvAddr); shmdt(pstRun->m_pvAddr);
pstRun->m_pvAddr = NULL; pstRun->m_pvAddr = NULL;
pstRun->m_bAttch = FALSE; pstRun->m_bAttch = false;
} }
return ; return ;
@ -1133,7 +1134,7 @@ void _vTblRelease(SATvm *pstSavm, TABLE t, bool bHold)
if(pstRun->m_pvAddr) if(pstRun->m_pvAddr)
shmdt(pstRun->m_pvAddr); shmdt(pstRun->m_pvAddr);
pstRun->m_pvAddr = NULL; pstRun->m_pvAddr = NULL;
pstRun->m_bAttch = FALSE; pstRun->m_bAttch = false;
} }
/************************************************************************************************* /*************************************************************************************************
@ -1477,7 +1478,7 @@ long lInitSvCache(SATvm *pstSavm)
pstRun->m_lLocal = pstIndex[i].m_lLocal; pstRun->m_lLocal = pstIndex[i].m_lLocal;
} }
pstSavm->m_bCache = TRUE; pstSavm->m_bCache = true;
TFree(pstIndex); TFree(pstIndex);
return RC_SUCC; return RC_SUCC;
@ -1647,7 +1648,7 @@ void* pInitHitTest(SATvm *pstSavm, TABLE t)
pstSavm->m_lErrno = 0; pstSavm->m_lErrno = 0;
pstSavm->m_lEffect= 0; pstSavm->m_lEffect= 0;
pstRun->m_bAttch = TRUE; pstRun->m_bAttch = true;
pstSavm->lSize = lGetRowSize(t); pstSavm->lSize = lGetRowSize(t);
memcpy((void *)pGetTblDef(t), pstRun->m_pvAddr, sizeof(TblDef)); memcpy((void *)pGetTblDef(t), pstRun->m_pvAddr, sizeof(TblDef));
@ -1720,7 +1721,7 @@ void* pInitMemTable(SATvm *pstSavm, TABLE t)
return NULL; return NULL;
} }
pstRun->m_bAttch = TRUE; pstRun->m_bAttch = true;
memcpy((void *)pGetTblDef(t), pstRun->m_pvAddr, sizeof(TblDef)); memcpy((void *)pGetTblDef(t), pstRun->m_pvAddr, sizeof(TblDef));
@ -1808,7 +1809,7 @@ void* pCreateBlock(SATvm *pstSavm, TABLE t, size_t lSize, bool bCreate)
} }
// memset(pstRun->m_pvAddr, 0, lSize); // memset(pstRun->m_pvAddr, 0, lSize);
pstRun->m_bAttch = TRUE; pstRun->m_bAttch = true;
return pstRun; return pstRun;
} }
@ -3777,7 +3778,7 @@ long __lDeleteHash(SATvm *pstSavm, void *pvAddr, SHTree *pstTree, TABLE t)
return RC_FAIL; return RC_FAIL;
} }
lReleaseTruck(pvAddr, t, pstTruck, TRUE); lReleaseTruck(pvAddr, t, pstTruck, true);
((TblDef *)pvAddr)->m_lValid --; ((TblDef *)pvAddr)->m_lValid --;
if(SELF_POS_UNUSE == lNext) break; if(SELF_POS_UNUSE == lNext) break;
@ -3943,7 +3944,7 @@ long __lDeleteIndex(SATvm *pstSavm, void *pvAddr, TABLE t, void *psvIdx)
return RC_FAIL; return RC_FAIL;
} }
lReleaseTruck(pvAddr, t, pstTruck, TRUE); lReleaseTruck(pvAddr, t, pstTruck, true);
pthread_rwlock_unlock(prwLock); pthread_rwlock_unlock(prwLock);
pstSavm->m_lEffect = 1; pstSavm->m_lEffect = 1;
@ -4080,7 +4081,7 @@ long __lDeleteGroup(SATvm *pstSavm, void *pvAddr, TABLE t, void *psvIdx)
return RC_FAIL; return RC_FAIL;
} }
lReleaseTruck(pvAddr, t, pstTruck, TRUE); lReleaseTruck(pvAddr, t, pstTruck, true);
((TblDef *)pvAddr)->m_lValid --; ((TblDef *)pvAddr)->m_lValid --;
if(SELF_POS_UNUSE == lNext) break; if(SELF_POS_UNUSE == lNext) break;
@ -4131,7 +4132,7 @@ long _lDeleteGroup(SATvm *pstSavm, void *pvAddr, TABLE t)
*************************************************************************************************/ *************************************************************************************************/
long _lDeleteTruck(SATvm *pstSavm, void *pvAddr, TABLE t) long _lDeleteTruck(SATvm *pstSavm, void *pvAddr, TABLE t)
{ {
bool bIsIdx = FALSE; bool bIsIdx = false;
SHTree *pstRoot = NULL; SHTree *pstRoot = NULL;
SHTruck *pstTruck = NULL; SHTruck *pstTruck = NULL;
char szIdx[MAX_INDEX_LEN]; char szIdx[MAX_INDEX_LEN];
@ -4139,7 +4140,7 @@ long _lDeleteTruck(SATvm *pstSavm, void *pvAddr, TABLE t)
size_t lData = 0, lOffset = lGetTblData(t), lIdx; size_t lData = 0, lOffset = lGetTblData(t), lIdx;
long lRow, lValid = ((TblDef *)pvAddr)->m_lValid; long lRow, lValid = ((TblDef *)pvAddr)->m_lValid;
if(HAVE_INDEX(t)) bIsIdx = TRUE; if(HAVE_INDEX(t)) bIsIdx = true;
if(RC_SUCC != pthread_rwlock_wrlock(prwLock)) if(RC_SUCC != pthread_rwlock_wrlock(prwLock))
{ {
@ -5038,6 +5039,8 @@ long _lRebuildIndex(SATvm *pstSavm, void *pvAddr)
lRow ++; lRow ++;
} }
((TblDef *)pvAddr)->m_lValid = lRow;
return RC_SUCC; return RC_SUCC;
} }
@ -8346,13 +8349,16 @@ long lStartupTvm(TBoot *pstBoot)
SATvm *pstSavm = (SATvm *)pGetSATvm(); SATvm *pstSavm = (SATvm *)pGetSATvm();
memset(&stIndex, 0, sizeof(TIndex)); memset(&stIndex, 0, sizeof(TIndex));
if(RC_SUCC != _lCreateTable(pstSavm, SYS_TVM_INDEX, pstBoot->m_lMaxTable, TRUE, if(RC_SUCC != _lCreateTable(pstSavm, SYS_TVM_INDEX, pstBoot->m_lMaxTable, true,
TYPE_SYSTEM, NULL)) TYPE_SYSTEM, NULL))
return RC_FAIL; return RC_FAIL;
pstRun = (RunTime *)pGetRunTime(pstSavm, SYS_TVM_INDEX); pstRun = (RunTime *)pGetRunTime(pstSavm, SYS_TVM_INDEX);
if(RC_SUCC != lCreateSems(pstSavm, pstRun, pstBoot->m_lMaxTable, SEM_INIT)) if(RC_SUCC != lCreateSems(pstSavm, pstRun, pstBoot->m_lMaxTable, SEM_INIT))
{
shmctl(pstRun->m_shmID, IPC_RMID, NULL);
return RC_FAIL; return RC_FAIL;
}
semID = pstRun->m_semID; semID = pstRun->m_semID;
stIndex.m_lValid = 0; stIndex.m_lValid = 0;
@ -8381,7 +8387,7 @@ long lStartupTvm(TBoot *pstBoot)
return RC_FAIL; return RC_FAIL;
memset(&stIndex, 0, sizeof(TIndex)); memset(&stIndex, 0, sizeof(TIndex));
if(RC_SUCC != _lCreateTable(pstSavm, SYS_TVM_FIELD, pstBoot->m_lMaxField, FALSE, if(RC_SUCC != _lCreateTable(pstSavm, SYS_TVM_FIELD, pstBoot->m_lMaxField, false,
TYPE_INCORE, NULL)) TYPE_INCORE, NULL))
return RC_FAIL; return RC_FAIL;
@ -8409,7 +8415,7 @@ long lStartupTvm(TBoot *pstBoot)
return RC_FAIL; return RC_FAIL;
memset(&stIndex, 0, sizeof(TIndex)); memset(&stIndex, 0, sizeof(TIndex));
if(RC_SUCC != _lCreateTable(pstSavm, SYS_TVM_DOMAIN, pstBoot->m_lMaxDomain, FALSE, if(RC_SUCC != _lCreateTable(pstSavm, SYS_TVM_DOMAIN, pstBoot->m_lMaxDomain, false,
TYPE_INCORE, NULL)) TYPE_INCORE, NULL))
return RC_FAIL; return RC_FAIL;
@ -8437,7 +8443,7 @@ long lStartupTvm(TBoot *pstBoot)
return RC_FAIL; return RC_FAIL;
memset(&stIndex, 0, sizeof(TIndex)); memset(&stIndex, 0, sizeof(TIndex));
if(RC_SUCC != _lCreateTable(pstSavm, SYS_TVM_SEQUE, pstBoot->m_lMaxSeque, FALSE, if(RC_SUCC != _lCreateTable(pstSavm, SYS_TVM_SEQUE, pstBoot->m_lMaxSeque, false,
TYPE_INCORE, NULL)) TYPE_INCORE, NULL))
return RC_FAIL; return RC_FAIL;
@ -8480,7 +8486,7 @@ long lStartupTvm(TBoot *pstBoot)
*************************************************************************************************/ *************************************************************************************************/
long lCreateTable(SATvm *pstSavm, TABLE t, size_t lRow, TCREATE pfCreateFunc) long lCreateTable(SATvm *pstSavm, TABLE t, size_t lRow, TCREATE pfCreateFunc)
{ {
return _lCreateTable(pstSavm, t, lRow, FALSE, TYPE_CLIENT, pfCreateFunc); return _lCreateTable(pstSavm, t, lRow, false, TYPE_CLIENT, pfCreateFunc);
} }
/************************************************************************************************* /*************************************************************************************************
@ -8499,7 +8505,7 @@ long lCustomTable(SATvm *pstSavm, TABLE t, size_t lRow, TblDef *pstDef)
memcpy((void *)pGetTblDef(t), (void *)pstDef, sizeof(TblDef)); memcpy((void *)pGetTblDef(t), (void *)pstDef, sizeof(TblDef));
return _lCustomTable(pstSavm, t, lRow, FALSE, TYPE_CLIENT); return _lCustomTable(pstSavm, t, lRow, false, TYPE_CLIENT);
} }
/************************************************************************************************* /*************************************************************************************************
@ -8623,8 +8629,7 @@ long _lExportContext(FILE *fp, char *s, long lIdx, TblKey *pstIdx, char *f)
} }
break; break;
case FIELD_CHAR: case FIELD_CHAR:
// fwrite(s + pstIdx[i].m_lFrom, 1, pstIdx[i].m_lLen, fp); fprintf(fp, "%.*s", pstIdx[i].m_lLen, s + pstIdx[i].m_lFrom);
fprintf(fp, "%s", s + pstIdx[i].m_lFrom);
break; break;
default: default:
fprintf(stderr, "Export field attribute exception\n"); fprintf(stderr, "Export field attribute exception\n");
@ -9194,10 +9199,10 @@ bool bIsTvmBoot()
pstRun->m_lLocal = RES_LOCAL_SID; pstRun->m_lLocal = RES_LOCAL_SID;
if(NULL == (pstRun = (RunTime *)pInitMemTable(pstSavm, pstSavm->tblName))) if(NULL == (pstRun = (RunTime *)pInitMemTable(pstSavm, pstSavm->tblName)))
return FALSE; return false;
vTblDisconnect(pstSavm, pstSavm->tblName); vTblDisconnect(pstSavm, pstSavm->tblName);
return TRUE; return true;
} }
/************************************************************************************************* /*************************************************************************************************
@ -9281,6 +9286,7 @@ long _lExtremGroup(SATvm *pstSavm, void *pvAddr, TABLE t, FdKey *pFdKey, void
return RC_FAIL; return RC_FAIL;
} }
pstSavm->m_lEffect = 1;
memcpy(psvOut + pFdKey->uFldpos, pvData + pFdKey->uFldpos, pFdKey->uFldlen); memcpy(psvOut + pFdKey->uFldpos, pvData + pFdKey->uFldpos, pFdKey->uFldlen);
return RC_SUCC; return RC_SUCC;
} }
@ -9342,6 +9348,7 @@ long _lExtremeHash(SATvm *pstSavm, void *pvAddr, TABLE t, FdKey *pFdKey, void
return RC_FAIL; return RC_FAIL;
} }
pstSavm->m_lEffect = 1;
memcpy(psvOut + pFdKey->uFldpos, pvData + pFdKey->uFldpos, pFdKey->uFldlen); memcpy(psvOut + pFdKey->uFldpos, pvData + pFdKey->uFldpos, pFdKey->uFldlen);
return RC_SUCC; return RC_SUCC;
} }
@ -9400,6 +9407,7 @@ long _lExtremeTruck(SATvm *pstSavm, void *pvAddr, TABLE t, FdKey *pFdKey, voi
return RC_FAIL; return RC_FAIL;
} }
pstSavm->m_lEffect = 1;
memcpy(psvOut + pFdKey->uFldpos, pvData + pFdKey->uFldpos, pFdKey->uFldlen); memcpy(psvOut + pFdKey->uFldpos, pvData + pFdKey->uFldpos, pFdKey->uFldlen);
return RC_SUCC; return RC_SUCC;
} }
@ -9453,6 +9461,7 @@ long _lExtremIndex(SATvm *pstSavm, void *pvAddr, TABLE t, FdKey *pFdKey, void
pstTruck = (PSHTruck)pGetNode(pvAddr, pstTree->m_lData); pstTruck = (PSHTruck)pGetNode(pvAddr, pstTree->m_lData);
memcpy(psvOut + pFdKey->uFldpos, pstTruck->m_pvData + pFdKey->uFldpos, pFdKey->uFldlen); memcpy(psvOut + pFdKey->uFldpos, pstTruck->m_pvData + pFdKey->uFldpos, pFdKey->uFldlen);
pstSavm->m_lEffect = 1;
return RC_SUCC; return RC_SUCC;
} }