├── README.md
├── doc
└── KSMDB用户手册.pdf
└── ksmdb
├── bin
├── linux
│ ├── backup
│ ├── errhandler
│ ├── ksmdb.ini
│ ├── ksmdbmanage
│ ├── kstbcmp
│ ├── multithread
│ ├── perf
│ └── simpleksmdb
└── windows
│ ├── backup.exe
│ ├── backup.pdb
│ ├── errhandler.exe
│ ├── errhandler.pdb
│ ├── ksmdb.dll
│ ├── ksmdbcli.dll
│ ├── ksmdbmanage32.exe
│ ├── ksmdbmanage64.exe
│ ├── kstbcmp.exe
│ ├── multithread.exe
│ ├── multithread.pdb
│ ├── perf.exe
│ ├── perf.pdb
│ ├── simpleksmdb.exe
│ └── simpleksmdb.pdb
├── etc
└── ksmdb.ini
├── include
├── cache.h
├── cachet.h
└── ksmdbclient.h
├── lib
├── linux
│ ├── libksmdb.a
│ ├── libksmdb.so
│ └── libksmdbcli.a
└── windows
│ ├── ksmdb32.lib
│ ├── ksmdb64.lib
│ └── ksmdbcli.lib
├── samples
├── backup
│ ├── backup.vcxproj
│ ├── build.sh
│ ├── db_def.ks
│ ├── grade
│ ├── grade.tb
│ ├── makefile
│ ├── qzh
│ ├── student.cpp
│ ├── student.h
│ ├── student.script
│ └── test.cpp
├── benchmark
│ ├── benchmark.vcxproj
│ ├── build.sh
│ ├── makefile
│ ├── perf.cpp
│ ├── perf.h
│ ├── perf.ks
│ ├── perf.script
│ └── testperf.cpp
├── errhandler
│ ├── build.sh
│ ├── db_def.ks
│ ├── errhandler.vcxproj
│ ├── grade
│ ├── grade.tb
│ ├── makefile
│ ├── qzh
│ ├── student.cpp
│ ├── student.h
│ ├── student.script
│ └── test.cpp
├── multithread
│ ├── build.sh
│ ├── db_def.ks
│ ├── grade
│ ├── grade.tb
│ ├── makefile
│ ├── multithread.vcxproj
│ ├── student.cpp
│ ├── student.h
│ ├── student.script
│ ├── studentdb
│ ├── test.cpp
│ ├── tools.c
│ └── tools.h
├── samples.ncb
├── samples.sln
├── samples.suo
└── simpleksmdb
│ ├── build.sh
│ ├── db_def.ks
│ ├── grade
│ ├── grade.tb
│ ├── makefile
│ ├── qzh
│ ├── simpleksmdb.vcxproj
│ ├── student.cpp
│ ├── student.h
│ ├── student.script
│ └── test.cpp
└── tool
├── clripc.sh
└── memoryclient
├── Configure.xml
├── Interop.Excel.dll
├── Interop.Office.dll
├── Kingstar.Common.dll
├── Kingstar.Core.dll
├── Kingstar.Toolkits.Common.dll
├── Kingstar.Toolkits.Controls.dll
├── Kingstar.Toolkits.Queue.dll
├── MemoryClient.exe
├── boost_thread.dll
└── ksmdbcli.dll
/README.md:
--------------------------------------------------------------------------------
1 | # 金仕达内存数据库体验版。
2 |
3 | ## 产品信息
4 | KSMDB是嵌入式内存数据库,可以为企业级服务器端应用系统和嵌入式系统提供高性能数据存取服务。
5 | KSMDB提供符合标准ACID规范的事务特性,由于数据存取访问路径足够短,KSMDB在高并发事务访问场景仍然具有极速性能表现。
6 |
7 | KSMDB对外表现为一个静态链接库。为了支持KSMDB静态链接库的开发与使用,该发布包同时包括工具集,文档,以及示例工程代码:
8 | - 静态库及工具文件包括:libksmdb.a, libksmdb.so, libksmdbcli.a, ksmdbmanage, kstbcmp,分别在ksmdb/lib,ksmdb/bin以及ksmdb/tool目录下。具体用法参见用户手册。
9 | - 示例工程及代码在ksmdb/samples目录下,包括基本接口的使用,性能,多线程,错误处理,导入导出(备份及恢复)。
10 |
11 | 当前版本: V2.3
12 |
13 | ## 支持的运行环境
14 | - Windows XP以上版本
15 | - Linux
16 | - 中标麒麟Linux(鲲鹏ARM64)
17 | - AIX
18 | - HP-UX
19 |
20 | 该体验版仅包含X86平台上Windows和通用Linux发布包,若需要AIX,HP-UX或其他平台的版本,请联系我们的技术支持。
21 |
22 | ## 技术社区和问题反馈
23 | - 技术支持QQ群:1048263371
24 | - 产品发布渠道:https://github.com/ksdbdev/ksmdb_eval
25 | - 技术支持邮箱:hongbin.zhu@kingstarfintech.com
26 | - 公司名称:上海金仕达软件科技有限公司
27 | - 公司地址:上海市浦东新区亮景路210号
28 |
--------------------------------------------------------------------------------
/doc/KSMDB用户手册.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/doc/KSMDB用户手册.pdf
--------------------------------------------------------------------------------
/ksmdb/bin/linux/backup:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/linux/backup
--------------------------------------------------------------------------------
/ksmdb/bin/linux/errhandler:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/linux/errhandler
--------------------------------------------------------------------------------
/ksmdb/bin/linux/ksmdb.ini:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/linux/ksmdb.ini
--------------------------------------------------------------------------------
/ksmdb/bin/linux/ksmdbmanage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/linux/ksmdbmanage
--------------------------------------------------------------------------------
/ksmdb/bin/linux/kstbcmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/linux/kstbcmp
--------------------------------------------------------------------------------
/ksmdb/bin/linux/multithread:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/linux/multithread
--------------------------------------------------------------------------------
/ksmdb/bin/linux/perf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/linux/perf
--------------------------------------------------------------------------------
/ksmdb/bin/linux/simpleksmdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/linux/simpleksmdb
--------------------------------------------------------------------------------
/ksmdb/bin/windows/backup.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/backup.exe
--------------------------------------------------------------------------------
/ksmdb/bin/windows/backup.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/backup.pdb
--------------------------------------------------------------------------------
/ksmdb/bin/windows/errhandler.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/errhandler.exe
--------------------------------------------------------------------------------
/ksmdb/bin/windows/errhandler.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/errhandler.pdb
--------------------------------------------------------------------------------
/ksmdb/bin/windows/ksmdb.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/ksmdb.dll
--------------------------------------------------------------------------------
/ksmdb/bin/windows/ksmdbcli.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/ksmdbcli.dll
--------------------------------------------------------------------------------
/ksmdb/bin/windows/ksmdbmanage32.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/ksmdbmanage32.exe
--------------------------------------------------------------------------------
/ksmdb/bin/windows/ksmdbmanage64.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/ksmdbmanage64.exe
--------------------------------------------------------------------------------
/ksmdb/bin/windows/kstbcmp.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/kstbcmp.exe
--------------------------------------------------------------------------------
/ksmdb/bin/windows/multithread.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/multithread.exe
--------------------------------------------------------------------------------
/ksmdb/bin/windows/multithread.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/multithread.pdb
--------------------------------------------------------------------------------
/ksmdb/bin/windows/perf.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/perf.exe
--------------------------------------------------------------------------------
/ksmdb/bin/windows/perf.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/perf.pdb
--------------------------------------------------------------------------------
/ksmdb/bin/windows/simpleksmdb.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/simpleksmdb.exe
--------------------------------------------------------------------------------
/ksmdb/bin/windows/simpleksmdb.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/bin/windows/simpleksmdb.pdb
--------------------------------------------------------------------------------
/ksmdb/etc/ksmdb.ini:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/etc/ksmdb.ini
--------------------------------------------------------------------------------
/ksmdb/include/cache.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/include/cache.h
--------------------------------------------------------------------------------
/ksmdb/include/cachet.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/include/cachet.h
--------------------------------------------------------------------------------
/ksmdb/include/ksmdbclient.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/include/ksmdbclient.h
--------------------------------------------------------------------------------
/ksmdb/lib/linux/libksmdb.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/lib/linux/libksmdb.a
--------------------------------------------------------------------------------
/ksmdb/lib/linux/libksmdb.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/lib/linux/libksmdb.so
--------------------------------------------------------------------------------
/ksmdb/lib/linux/libksmdbcli.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/lib/linux/libksmdbcli.a
--------------------------------------------------------------------------------
/ksmdb/lib/windows/ksmdb32.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/lib/windows/ksmdb32.lib
--------------------------------------------------------------------------------
/ksmdb/lib/windows/ksmdb64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/lib/windows/ksmdb64.lib
--------------------------------------------------------------------------------
/ksmdb/lib/windows/ksmdbcli.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/lib/windows/ksmdbcli.lib
--------------------------------------------------------------------------------
/ksmdb/samples/backup/backup.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {3FB3A0F5-2309-47D7-ADAA-4458C2AF0C58}
15 | backup
16 | Win32Proj
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | v141
23 | Unicode
24 | true
25 |
26 |
27 | Application
28 | v141
29 | Unicode
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | <_ProjectFileVersion>15.0.28307.799
43 |
44 |
45 | $(SolutionDir)$(Configuration)\
46 | $(Configuration)\
47 | true
48 |
49 |
50 | $(SolutionDir)$(Configuration)\
51 | $(Configuration)\
52 | false
53 |
54 |
55 |
56 | Disabled
57 | ..\..\include;%(AdditionalIncludeDirectories)
58 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
59 | true
60 | EnableFastChecks
61 | MultiThreadedDebugDLL
62 |
63 | Level3
64 | EditAndContinue
65 |
66 |
67 | ksmdb.lib;%(AdditionalDependencies)
68 | $(SolutionDir)..\bin\backup.exe
69 | ..\..\lib\windows;%(AdditionalLibraryDirectories)
70 | true
71 | Console
72 | MachineX86
73 |
74 |
75 |
76 |
77 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
78 | MultiThreadedDLL
79 |
80 | Level3
81 | ProgramDatabase
82 | $(SolutionDir)\..\include;%(AdditionalIncludeDirectories)
83 |
84 |
85 | true
86 | Console
87 | true
88 | true
89 | MachineX86
90 | $(SolutionDir)/../lib/windows/
91 | ksmdb32.lib;ws2_32.lib;%(AdditionalDependencies)
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/ksmdb/samples/backup/build.sh:
--------------------------------------------------------------------------------
1 | ../../bin/linux/kstbcmp db_def.ks student
2 |
3 | make
4 |
--------------------------------------------------------------------------------
/ksmdb/samples/backup/db_def.ks:
--------------------------------------------------------------------------------
1 | declare database student;
2 | class grade
3 | {
4 | int4 id;
5 | string<50> name;
6 | string<10> classroom;
7 | double<0> math;
8 | double<0> Chinese;
9 | double<0> english;
10 | unique tree pkey;
11 | tree nameindex;
12 | tree classroom;
13 | tree nameclassroom;
14 | };
15 |
--------------------------------------------------------------------------------
/ksmdb/samples/backup/grade:
--------------------------------------------------------------------------------
1 | origin_index_name=pkey(id)
2 | origin_index_name=nameindex(name)
3 | origin_index_name=classroom(classroom)
4 | origin_index_name=nameclassroom(name,classroom)
5 | curent_index_name=pkey(id)
6 | curent_index_name=nameindex(name)
7 | curent_index_name=classroom(classroom)
8 | curent_index_name=nameclassroom(name,classroom)
9 | tablename=grade(id,name,classroom,math,Chinese,english)
10 |
--------------------------------------------------------------------------------
/ksmdb/samples/backup/grade.tb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/backup/grade.tb
--------------------------------------------------------------------------------
/ksmdb/samples/backup/makefile:
--------------------------------------------------------------------------------
1 | CXX = g++
2 | CXXFLAGS = -g
3 | LINK = $(CXX)
4 |
5 | INCLD = -I../../include
6 | LIBS = -L../../lib/linux -lksmdb -lm -lrt -lstdc++ -lpthread
7 |
8 | TARGET = backup
9 |
10 | OBJS = student.o test.o
11 |
12 | all:$(TARGET)
13 |
14 | backup:$(OBJS)
15 | $(LINK) -static -o backup $(OBJS) $(INCLD) $(LIBS)
16 | rm -rf *.o
17 |
18 | .cpp.o:
19 | $(CXX) $(CXXFLAGS) $(INCLD) -c $< -o $@
20 |
21 | clean:
22 | rm -f *.o
23 | rm -f backup
24 |
25 |
--------------------------------------------------------------------------------
/ksmdb/samples/backup/qzh:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/backup/qzh
--------------------------------------------------------------------------------
/ksmdb/samples/backup/student.cpp:
--------------------------------------------------------------------------------
1 | #include "student.h"
2 | DB_student::DB_student()
3 | {
4 | m_inited = false;
5 | m_database = NULL;
6 | }
7 |
8 | bool DB_student::Create(char *path,char *name,size_t size)
9 | {
10 | if(m_inited)
11 | {
12 | return true;
13 | }
14 | m_inited=true;
15 | if (KsCreateDb(&m_database,path,name,"20210423-10:14:30:000",size) == true)
16 | {
17 | KsAddTable(m_database,"grade");
18 | KsAddField(m_database,0,"id",KSTYPE_INT4,4,-1);
19 | KsAddField(m_database,0,"name",KSTYPE_STRING,51,-1);
20 | KsAddField(m_database,0,"classroom",KSTYPE_STRING,11,-1);
21 | KsAddField(m_database,0,"math",KSTYPE_DOUBLE,8,0);
22 | KsAddField(m_database,0,"Chinese",KSTYPE_DOUBLE,8,0);
23 | KsAddField(m_database,0,"english",KSTYPE_DOUBLE,8,0);
24 | KsAddIndex(m_database,0,"pkey",UNIQUE_INDEX);
25 | KsAddIndexField(m_database,0,0,0);
26 | KsAddIndex(m_database,0,"nameindex",NONUNIQUE_INDEX);
27 | KsAddIndexField(m_database,0,1,1);
28 | KsAddIndex(m_database,0,"classroom",NONUNIQUE_INDEX);
29 | KsAddIndexField(m_database,0,2,2);
30 | KsAddIndex(m_database,0,"nameclassroom",NONUNIQUE_INDEX);
31 | KsAddIndexField(m_database,0,3,1);
32 | KsAddIndexField(m_database,0,3,2);
33 | KsSaveDbInfo(m_database);
34 | }
35 | else
36 | {
37 | m_inited=false;
38 | return false;
39 | }
40 | KsLoadDb(m_database);
41 | return true;
42 | };
43 |
44 | bool DB_student::Open(char *path,char *name,int mode,int port,bool isolate,int reuse_shmmap, int shmrcset_mode)
45 | {
46 | if(m_inited)
47 | {
48 | return true;
49 | }
50 | m_inited=true;
51 | if (KsOpenDb(&m_database,path,name,"20210423-10:14:30:000",mode,port,isolate, reuse_shmmap, shmrcset_mode) == true)
52 | {
53 | KsLoadDbInfo(m_database);
54 | }
55 | else
56 | {
57 | m_inited=false;
58 | return false;
59 | }
60 | KsLoadDb(m_database);
61 | return true;
62 | };
63 |
64 | void DB_student::UnLockDb()
65 | {
66 | KsUnLockDb(m_database);
67 | }
68 |
69 | void DB_student::SetErrorHandle(KsErrorHandle handle)
70 | {
71 | KsSetErrorHandle(m_database,handle);
72 | }
73 |
74 | int DB_student::GetCols(KsRecordHandle handle)
75 | {
76 | return KsGetCols(m_database,handle);
77 | }
78 |
79 | char *DB_student::GetColName(KsRecordHandle handle,int col)
80 | {
81 | return KsGetColName(m_database,handle,col);
82 | }
83 |
84 | int DB_student::GetColType(KsRecordHandle handle,int col)
85 | {
86 | return KsGetColType(m_database,handle,col);
87 | }
88 |
89 | int DB_student::GetColSize(KsRecordHandle handle,int col)
90 | {
91 | return KsGetColSize(m_database,handle,col);
92 | }
93 |
94 | int DB_student::GetColDecimal(KsRecordHandle handle,int col)
95 | {
96 | return KsGetColDecimal(m_database,handle,col);
97 | }
98 |
99 | char *DB_student::GetColData(KsRecordHandle handle,int col)
100 | {
101 | return KsGetColData(m_database,handle,col);
102 | }
103 |
104 | void DB_student::GetMemoryInfo(size_t &size,size_t &inused)
105 | {
106 | KsMemoryInfo(m_database,&size,&inused);
107 | }
108 |
109 | void DB_student::Reset()
110 | {
111 | KsResetDb(m_database);
112 | }
113 |
114 | bool DB_student::Backup(char *filename)
115 | {
116 | return KsWriteDbFile(m_database,filename);
117 | }
118 |
119 | bool DB_student::Load(char *filename)
120 | {
121 | return KsReadDbFile(m_database,filename);
122 | }
123 |
124 | void DB_student::BeginTransaction()
125 | {
126 | KsBeginTransaction(m_database);
127 | }
128 |
129 | void DB_student::RollbackTransaction()
130 | {
131 | KsRollbackTransaction(m_database);
132 | }
133 |
134 | void DB_student::CommitTransaction()
135 | {
136 | KsCommitTransaction(m_database);
137 | }
138 |
139 | void DB_student::GetLastError(int *errcode,char *errmsg)
140 | {
141 | KsGetError(m_database,*errcode,errmsg);
142 | }
143 |
144 | void DB_student::Close()
145 | {
146 | KsDeleteDb(m_database);
147 | m_inited=false;
148 | }
149 |
150 | char* DB_student::LibVersion()
151 | {
152 | return KsGetLibVersion();
153 | }
154 |
155 | char* DB_student::DbVersion()
156 | {
157 | return KsGetDbVersion(m_database);
158 | }
159 |
160 | KsDbHandle DB_student::GetDBHandle()
161 | {
162 | return m_database;
163 | }
164 |
165 | TB_grade::TB_grade(KsDbHandle database)
166 | {
167 | m_database = database;
168 | KsCreateCondition(2,&m_condition);
169 | KsCreateRecord(&m_record);
170 | }
171 |
172 | TB_grade::TB_grade(TB_grade &V)
173 | {
174 | KsCreateCondition(2,&m_condition);
175 | KsCreateRecord(&m_record);
176 | KsDupCondition(V.m_condition,m_condition);
177 | KsDupRecord(V.m_record,m_record);
178 | }
179 |
180 | TB_grade::~TB_grade()
181 | {
182 | KsCloseCondition(m_condition);
183 | KsCloseRecord(m_database,m_record);
184 | }
185 |
186 | bool TB_grade::newrecord()
187 | {
188 | return KsNewRecord(m_database,0,m_record);
189 | }
190 |
191 | bool TB_grade::append(int id,char* name,char* classroom)
192 | {
193 | KsSetField(m_database,m_record,0,(char *)&id);
194 | KsSetField(m_database,m_record,1,(char *)name);
195 | KsSetField(m_database,m_record,2,(char *)classroom);
196 | return KsPutRecord(m_database,m_record);
197 | }
198 |
199 | bool TB_grade::erase()
200 | {
201 | KsDeleteRecord(m_database,m_record);
202 | return true;
203 | }
204 |
205 | bool TB_grade::first()
206 | {
207 | if(!KsFirstRecord(m_database,m_condition))
208 | {
209 | return false;
210 | }
211 | KsGetRecord(m_database,m_condition,m_record);
212 | return true;
213 | }
214 |
215 | bool TB_grade::prev()
216 | {
217 | if(!KsPrevRecord(m_database,m_condition))
218 | {
219 | return false;
220 | }
221 | KsGetRecord(m_database,m_condition,m_record);
222 | return true;
223 | }
224 |
225 | bool TB_grade::next()
226 | {
227 | if(!KsNextRecord(m_database,m_condition))
228 | {
229 | return false;
230 | }
231 | KsGetRecord(m_database,m_condition,m_record);
232 | return true;
233 | }
234 |
235 | bool TB_grade::end()
236 | {
237 | if(!KsLastRecord(m_database,m_condition))
238 | {
239 | return false;
240 | }
241 | KsGetRecord(m_database,m_condition,m_record);
242 | return true;
243 | }
244 |
245 | bool TB_grade::gotorow(int rowid)
246 | {
247 | if(!KsGotoRecord(m_database,0,rowid,m_condition))
248 | {
249 | return false;
250 | }
251 | KsGetRecord(m_database,m_condition,m_record);
252 | return true;
253 | }
254 |
255 | int TB_grade::recordrowid()
256 | {
257 | return KsGetRecordId(m_database,m_record);
258 | }
259 |
260 | bool TB_grade::dump(char *filename)
261 | {
262 | return KsDumpTable(m_database,0,filename);
263 | }
264 |
265 | bool TB_grade::SaveCsv(char *filename)
266 | {
267 | return KsWriteTableCsv(m_database,0,filename);
268 | }
269 |
270 | bool TB_grade::LoadCsv(char *filename)
271 | {
272 | return KsReadTableCsv(m_database,0,m_record,filename);
273 | }
274 |
275 | bool TB_grade::SaveTXT(char *filename)
276 | {
277 | return KsWriteTableTxt(m_database,0,filename);
278 | }
279 |
280 | bool TB_grade::LoadTXT(char *filename)
281 | {
282 | return KsReadTableTxt(m_database,0,m_record,filename);
283 | }
284 |
285 | bool TB_grade::SaveBinary(char *filename)
286 | {
287 | return KsWriteTableBinary(m_database,0,filename);
288 | }
289 |
290 | bool TB_grade::LoadBinary(char *filename)
291 | {
292 | return KsReadTableBinary(m_database,0,m_record,filename);
293 | }
294 |
295 | bool TB_grade::backup(char *filename)
296 | {
297 | return KsWriteDbTable(m_database,0,filename);
298 | }
299 |
300 | bool TB_grade::load(char *filename)
301 | {
302 | return KsReadDbTable(m_database,0,filename);
303 | }
304 |
305 | int TB_grade::get_id()
306 | {
307 | int fieldtype;
308 | int r;
309 |
310 | memcpy(&r,KsGetField(m_database,m_record,0,fieldtype),sizeof(int));
311 | return r;
312 | }
313 |
314 | char* TB_grade::get_name()
315 | {
316 | int fieldtype;
317 |
318 | return (char *)KsGetField(m_database,m_record,1,fieldtype);
319 | }
320 |
321 | char* TB_grade::get_classroom()
322 | {
323 | int fieldtype;
324 |
325 | return (char *)KsGetField(m_database,m_record,2,fieldtype);
326 | }
327 |
328 | bool TB_grade::set_math(double value)
329 | {
330 | return KsSetField(m_database,m_record,3,(char *)&value);
331 | }
332 |
333 | double TB_grade::get_math()
334 | {
335 | int fieldtype;
336 | double r;
337 |
338 | memcpy(&r,KsGetField(m_database,m_record,3,fieldtype),sizeof(double));
339 | return r;
340 | }
341 |
342 | bool TB_grade::set_Chinese(double value)
343 | {
344 | return KsSetField(m_database,m_record,4,(char *)&value);
345 | }
346 |
347 | double TB_grade::get_Chinese()
348 | {
349 | int fieldtype;
350 | double r;
351 |
352 | memcpy(&r,KsGetField(m_database,m_record,4,fieldtype),sizeof(double));
353 | return r;
354 | }
355 |
356 | bool TB_grade::set_english(double value)
357 | {
358 | return KsSetField(m_database,m_record,5,(char *)&value);
359 | }
360 |
361 | double TB_grade::get_english()
362 | {
363 | int fieldtype;
364 | double r;
365 |
366 | memcpy(&r,KsGetField(m_database,m_record,5,fieldtype),sizeof(double));
367 | return r;
368 | }
369 |
370 | bool TB_grade::find_by_pkey(int id,int op)
371 | {
372 | KsSetConditionIndex(m_condition,0);
373 | KsAddConditionIndexItem(m_condition,KSTYPE_INT4,4,(char *)&id);
374 | if (!KsFindRecord(m_database,0,m_condition,op))
375 | {
376 | return false;
377 | }
378 | KsGetRecord(m_database,m_condition,m_record);
379 | return true;
380 | }
381 |
382 | bool TB_grade::find_by_nameindex(char* name,int op)
383 | {
384 | KsSetConditionIndex(m_condition,1);
385 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,51,(char *)name);
386 | if (!KsFindRecord(m_database,0,m_condition,op))
387 | {
388 | return false;
389 | }
390 | KsGetRecord(m_database,m_condition,m_record);
391 | return true;
392 | }
393 |
394 | bool TB_grade::find_by_classroom(char* classroom,int op)
395 | {
396 | KsSetConditionIndex(m_condition,2);
397 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,11,(char *)classroom);
398 | if (!KsFindRecord(m_database,0,m_condition,op))
399 | {
400 | return false;
401 | }
402 | KsGetRecord(m_database,m_condition,m_record);
403 | return true;
404 | }
405 |
406 | bool TB_grade::find_by_nameclassroom(char* name,char* classroom,int op)
407 | {
408 | KsSetConditionIndex(m_condition,3);
409 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,51,(char *)name);
410 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,11,(char *)classroom);
411 | if (!KsFindRecord(m_database,0,m_condition,op))
412 | {
413 | return false;
414 | }
415 | KsGetRecord(m_database,m_condition,m_record);
416 | return true;
417 | }
418 |
419 | bool TB_grade::lists()
420 | {
421 | KsSetConditionIndex(m_condition,-1);
422 | if (!KsListRecord(m_database,0,m_condition))
423 | {
424 | return false;
425 | }
426 | KsGetRecord(m_database,m_condition,m_record);
427 | return true;
428 | }
429 |
430 | bool TB_grade::list_by_pkey()
431 | {
432 | KsSetConditionIndex(m_condition,0);
433 | if (!KsListRecord(m_database,0,m_condition))
434 | {
435 | return false;
436 | }
437 | KsGetRecord(m_database,m_condition,m_record);
438 | return true;
439 | }
440 |
441 | bool TB_grade::list_by_nameindex()
442 | {
443 | KsSetConditionIndex(m_condition,1);
444 | if (!KsListRecord(m_database,0,m_condition))
445 | {
446 | return false;
447 | }
448 | KsGetRecord(m_database,m_condition,m_record);
449 | return true;
450 | }
451 |
452 | bool TB_grade::list_by_classroom()
453 | {
454 | KsSetConditionIndex(m_condition,2);
455 | if (!KsListRecord(m_database,0,m_condition))
456 | {
457 | return false;
458 | }
459 | KsGetRecord(m_database,m_condition,m_record);
460 | return true;
461 | }
462 |
463 | bool TB_grade::list_by_nameclassroom()
464 | {
465 | KsSetConditionIndex(m_condition,3);
466 | if (!KsListRecord(m_database,0,m_condition))
467 | {
468 | return false;
469 | }
470 | KsGetRecord(m_database,m_condition,m_record);
471 | return true;
472 | }
473 |
474 |
--------------------------------------------------------------------------------
/ksmdb/samples/backup/student.h:
--------------------------------------------------------------------------------
1 | #ifndef __student_HH
2 | #define __student_HH
3 | #include "cache.h"
4 | #include
5 | class DB_student
6 | {
7 | private:
8 | bool m_inited;
9 | KsDbHandle m_database;
10 | public:
11 | DB_student();
12 | virtual ~DB_student(){};
13 | bool Create(char *path,char *name,size_t size);
14 | bool Open(char *path,char *name,int mode,int port,bool isolate, int reuse_shmmap, int shmrcset_mode=0);
15 | void UnLockDb();
16 | void SetErrorHandle(KsErrorHandle handle);
17 | int GetCols(KsRecordHandle handle);
18 | char *GetColName(KsRecordHandle handle,int col);
19 | int GetColType(KsRecordHandle handle,int col);
20 | int GetColSize(KsRecordHandle handle,int col);
21 | int GetColDecimal(KsRecordHandle handle,int col);
22 | char *GetColData(KsRecordHandle handle,int col);
23 | void GetMemoryInfo(size_t &size,size_t &inused);
24 | void Reset();
25 | bool Backup(char *filename);
26 | bool Load(char *filename);
27 | void BeginTransaction();
28 | void RollbackTransaction();
29 | void CommitTransaction();
30 | void GetLastError(int *errcode,char *errmsg);
31 | void Close();
32 | char *LibVersion();
33 | char *DbVersion();
34 | KsDbHandle GetDBHandle();
35 | };
36 |
37 | class TB_grade
38 | {
39 | private:
40 | KsDbHandle m_database;
41 | public:
42 | KsRecordHandle m_record;
43 | KsConditionHandle m_condition;
44 | public:
45 | TB_grade(KsDbHandle database);
46 | TB_grade(TB_grade &V);
47 | virtual ~TB_grade();
48 | bool newrecord();
49 | bool append(int id,char* name,char* classroom);
50 | bool erase();
51 | bool first();
52 | bool prev();
53 | bool next();
54 | bool end();
55 | bool gotorow(int rowid);
56 | int recordrowid();
57 | bool dump(char *filename="grade");
58 | bool SaveCsv(char *filename="grade.csv");
59 | bool LoadCsv(char *filename="grade.csv");
60 | bool SaveTXT(char *filename="grade.txt");
61 | bool LoadTXT(char *filename="grade.txt");
62 | bool SaveBinary(char *filename="grade.txt");
63 | bool LoadBinary(char *filename="grade.txt");
64 | bool backup(char *filename="grade");
65 | bool load(char *filename="grade");
66 | int get_id();
67 | char* get_name();
68 | char* get_classroom();
69 | bool set_math(double value);
70 | double get_math();
71 | bool set_Chinese(double value);
72 | double get_Chinese();
73 | bool set_english(double value);
74 | double get_english();
75 | bool find_by_pkey(int id,int op=EQ);
76 | bool find_by_nameindex(char* name,int op=EQ);
77 | bool find_by_classroom(char* classroom,int op=EQ);
78 | bool find_by_nameclassroom(char* name,char* classroom,int op=EQ);
79 | bool lists();
80 | bool list_by_pkey();
81 | bool list_by_nameindex();
82 | bool list_by_classroom();
83 | bool list_by_nameclassroom();
84 | };
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/ksmdb/samples/backup/student.script:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/backup/student.script
--------------------------------------------------------------------------------
/ksmdb/samples/backup/test.cpp:
--------------------------------------------------------------------------------
1 | #include "student.h"
2 | #include
3 | #if defined(WIN32)
4 | #include
5 | #endif
6 | bool myerrhandle(int errcode,char *errmsg)
7 | {
8 | printf("my errhandle:errcode=%d,errmsg=%s\n",errcode,errmsg);
9 | return true;
10 | }
11 |
12 | int main(int argc,char **argv)
13 | {
14 | DB_student studentdb;
15 | size_t size,inused;
16 | int errcode;
17 | int i;
18 | char errmsg[300];
19 | char name[20];
20 | char room[20];
21 |
22 | if (studentdb.Create(".","qzh",1000000) == false)
23 | {
24 | studentdb.GetLastError(&errcode,errmsg);
25 | printf("errcode=%d,errmsg=%s\n",errcode,errmsg);
26 | return 0;
27 | }
28 | studentdb.UnLockDb();
29 |
30 | studentdb.SetErrorHandle(myerrhandle);
31 |
32 | printf("database is created.\n");
33 |
34 | TB_grade grade(studentdb.GetDBHandle());
35 |
36 | studentdb.BeginTransaction();
37 |
38 | for (i=0; i<100; i++)
39 | {
40 | grade.newrecord();
41 | grade.set_math(i);
42 | grade.set_Chinese(i);
43 | grade.set_english(i);
44 | sprintf(name,"%d",i % 10);
45 | sprintf(room,"%d",i % 10);
46 | grade.append(i,name,room);
47 | }
48 | studentdb.CommitTransaction();
49 | printf("insert data into table succeed.\n");
50 |
51 | studentdb.GetMemoryInfo(size,inused);
52 | printf("database size=%d,inused=%d\n",size,inused);
53 | studentdb.BeginTransaction();
54 | grade.backup("grade.tb");
55 | printf("table backup succeed.\n");
56 | printf("press any key to continue...\n");
57 | getc(stdin);
58 | studentdb.Reset();
59 | grade.load("grade.tb");
60 | printf("table load succeed.\n");
61 |
62 | studentdb.CommitTransaction();
63 |
64 | studentdb.BeginTransaction();
65 | if (grade.find_by_nameindex("12",LARGE_EQ))
66 | {
67 | grade.end();
68 | do
69 | {
70 | printf("FindById: id=%d,name=%s,classroom=%s,math=%4.1f,chinese=%4.1f,english=%4.1f\n",
71 | grade.get_id(),grade.get_name(),grade.get_classroom(),
72 | grade.get_math(),grade.get_Chinese(),grade.get_english());
73 | }while(grade.prev());
74 | }
75 | else
76 | {
77 | printf("not found\n");
78 | }
79 | studentdb.CommitTransaction();
80 |
81 | studentdb.GetMemoryInfo(size,inused);
82 | printf("size=%d,inused=%d\n",size,inused);
83 | studentdb.Close();
84 | printf("database is closed.\n");
85 | printf("press any key to quit...\n");
86 |
87 | getc(stdin);
88 | return 0;
89 | }
90 |
--------------------------------------------------------------------------------
/ksmdb/samples/benchmark/benchmark.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {02F72C85-3C82-4936-897E-752698B6E43D}
15 | benchmark
16 | Win32Proj
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | v141
23 | Unicode
24 | true
25 |
26 |
27 | Application
28 | v141
29 | Unicode
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | <_ProjectFileVersion>15.0.28307.799
43 |
44 |
45 | $(SolutionDir)$(Configuration)\
46 | $(Configuration)\
47 | true
48 |
49 |
50 | $(SolutionDir)$(Configuration)\
51 | $(Configuration)\
52 | false
53 |
54 |
55 |
56 | Disabled
57 | ..\..\include;%(AdditionalIncludeDirectories)
58 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
59 | true
60 | EnableFastChecks
61 | MultiThreadedDebugDLL
62 |
63 | .\Debug/perf.pch
64 | Level3
65 | EditAndContinue
66 |
67 |
68 | ws2_32.lib;odbc32.lib;odbccp32.lib;ksmdb.lib;%(AdditionalDependencies)
69 | $(SolutionDir)..\bin\perf.exe
70 | ..\..\lib\windows;%(AdditionalLibraryDirectories)
71 | true
72 | Console
73 | MachineX86
74 |
75 |
76 |
77 |
78 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
79 | MultiThreadedDLL
80 |
81 | Level3
82 | ProgramDatabase
83 | $(SolutionDir)\..\include
84 |
85 |
86 | true
87 | Console
88 | true
89 | true
90 | MachineX86
91 | ksmdb32.lib;ws2_32.lib;%(AdditionalDependencies)
92 | $(SolutionDir)/../lib/windows/
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/ksmdb/samples/benchmark/build.sh:
--------------------------------------------------------------------------------
1 | ../../bin/linux/kstbcmp perf.ks perf
2 |
3 | make
4 |
--------------------------------------------------------------------------------
/ksmdb/samples/benchmark/makefile:
--------------------------------------------------------------------------------
1 | CXX = g++
2 | CXXFLAGS = -g
3 | LINK = $(CXX)
4 |
5 | INCLD = -I../../include
6 | LIBS = -L../../lib/linux -lksmdb -lm -lrt -lstdc++ -lpthread
7 |
8 | TARGET = perf
9 |
10 | OBJS = perf.o testperf.o
11 |
12 | all:$(TARGET)
13 |
14 | perf:$(OBJS)
15 | $(LINK) -static -o perf $(OBJS) $(INCLD) $(LIBS)
16 | rm -rf *.o
17 |
18 | .cpp.o:
19 | $(CXX) $(CXXFLAGS) $(INCLD) -c $< -o $@
20 |
21 | clean:
22 | rm -f *.o
23 | rm -f perf
24 |
25 |
--------------------------------------------------------------------------------
/ksmdb/samples/benchmark/perf.cpp:
--------------------------------------------------------------------------------
1 | #include "perf.h"
2 | DB_perf::DB_perf()
3 | {
4 | m_inited = false;
5 | m_database = NULL;
6 | }
7 |
8 | bool DB_perf::Create(char *path,char *name,size_t size)
9 | {
10 | if(m_inited)
11 | {
12 | return true;
13 | }
14 | m_inited=true;
15 | if (KsCreateDb(&m_database,path,name,"20210423-10:52:06:000",size) == true)
16 | {
17 | KsAddTable(m_database,"grade");
18 | KsAddField(m_database,0,"id",KSTYPE_INT4,4,-1);
19 | KsAddField(m_database,0,"value",KSTYPE_INT4,4,-1);
20 | KsAddIndex(m_database,0,"pkey",UNIQUE_INDEX);
21 | KsAddIndexField(m_database,0,0,0);
22 | KsSaveDbInfo(m_database);
23 | }
24 | else
25 | {
26 | m_inited=false;
27 | return false;
28 | }
29 | KsLoadDb(m_database);
30 | return true;
31 | };
32 |
33 | bool DB_perf::Open(char *path,char *name,int mode,int port,bool isolate,int reuse_shmmap, int shmrcset_mode)
34 | {
35 | if(m_inited)
36 | {
37 | return true;
38 | }
39 | m_inited=true;
40 | if (KsOpenDb(&m_database,path,name,"20210423-10:52:06:000",mode,port,isolate, reuse_shmmap, shmrcset_mode) == true)
41 | {
42 | KsLoadDbInfo(m_database);
43 | }
44 | else
45 | {
46 | m_inited=false;
47 | return false;
48 | }
49 | KsLoadDb(m_database);
50 | return true;
51 | };
52 |
53 | void DB_perf::UnLockDb()
54 | {
55 | KsUnLockDb(m_database);
56 | }
57 |
58 | void DB_perf::SetErrorHandle(KsErrorHandle handle)
59 | {
60 | KsSetErrorHandle(m_database,handle);
61 | }
62 |
63 | int DB_perf::GetCols(KsRecordHandle handle)
64 | {
65 | return KsGetCols(m_database,handle);
66 | }
67 |
68 | char *DB_perf::GetColName(KsRecordHandle handle,int col)
69 | {
70 | return KsGetColName(m_database,handle,col);
71 | }
72 |
73 | int DB_perf::GetColType(KsRecordHandle handle,int col)
74 | {
75 | return KsGetColType(m_database,handle,col);
76 | }
77 |
78 | int DB_perf::GetColSize(KsRecordHandle handle,int col)
79 | {
80 | return KsGetColSize(m_database,handle,col);
81 | }
82 |
83 | int DB_perf::GetColDecimal(KsRecordHandle handle,int col)
84 | {
85 | return KsGetColDecimal(m_database,handle,col);
86 | }
87 |
88 | char *DB_perf::GetColData(KsRecordHandle handle,int col)
89 | {
90 | return KsGetColData(m_database,handle,col);
91 | }
92 |
93 | void DB_perf::GetMemoryInfo(size_t &size,size_t &inused)
94 | {
95 | KsMemoryInfo(m_database,&size,&inused);
96 | }
97 |
98 | void DB_perf::Reset()
99 | {
100 | KsResetDb(m_database);
101 | }
102 |
103 | bool DB_perf::Backup(char *filename)
104 | {
105 | return KsWriteDbFile(m_database,filename);
106 | }
107 |
108 | bool DB_perf::Load(char *filename)
109 | {
110 | return KsReadDbFile(m_database,filename);
111 | }
112 |
113 | void DB_perf::BeginTransaction()
114 | {
115 | KsBeginTransaction(m_database);
116 | }
117 |
118 | void DB_perf::RollbackTransaction()
119 | {
120 | KsRollbackTransaction(m_database);
121 | }
122 |
123 | void DB_perf::CommitTransaction()
124 | {
125 | KsCommitTransaction(m_database);
126 | }
127 |
128 | void DB_perf::GetLastError(int *errcode,char *errmsg)
129 | {
130 | KsGetError(m_database,*errcode,errmsg);
131 | }
132 |
133 | void DB_perf::Close()
134 | {
135 | KsDeleteDb(m_database);
136 | m_inited=false;
137 | }
138 |
139 | char* DB_perf::LibVersion()
140 | {
141 | return KsGetLibVersion();
142 | }
143 |
144 | char* DB_perf::DbVersion()
145 | {
146 | return KsGetDbVersion(m_database);
147 | }
148 |
149 | KsDbHandle DB_perf::GetDBHandle()
150 | {
151 | return m_database;
152 | }
153 |
154 | TB_grade::TB_grade(KsDbHandle database)
155 | {
156 | m_database = database;
157 | KsCreateCondition(1,&m_condition);
158 | KsCreateRecord(&m_record);
159 | }
160 |
161 | TB_grade::TB_grade(TB_grade &V)
162 | {
163 | KsCreateCondition(1,&m_condition);
164 | KsCreateRecord(&m_record);
165 | KsDupCondition(V.m_condition,m_condition);
166 | KsDupRecord(V.m_record,m_record);
167 | }
168 |
169 | TB_grade::~TB_grade()
170 | {
171 | KsCloseCondition(m_condition);
172 | KsCloseRecord(m_database,m_record);
173 | }
174 |
175 | bool TB_grade::newrecord()
176 | {
177 | return KsNewRecord(m_database,0,m_record);
178 | }
179 |
180 | bool TB_grade::append(int id)
181 | {
182 | KsSetField(m_database,m_record,0,(char *)&id);
183 | return KsPutRecord(m_database,m_record);
184 | }
185 |
186 | bool TB_grade::erase()
187 | {
188 | KsDeleteRecord(m_database,m_record);
189 | return true;
190 | }
191 |
192 | bool TB_grade::first()
193 | {
194 | if(!KsFirstRecord(m_database,m_condition))
195 | {
196 | return false;
197 | }
198 | KsGetRecord(m_database,m_condition,m_record);
199 | return true;
200 | }
201 |
202 | bool TB_grade::prev()
203 | {
204 | if(!KsPrevRecord(m_database,m_condition))
205 | {
206 | return false;
207 | }
208 | KsGetRecord(m_database,m_condition,m_record);
209 | return true;
210 | }
211 |
212 | bool TB_grade::next()
213 | {
214 | if(!KsNextRecord(m_database,m_condition))
215 | {
216 | return false;
217 | }
218 | KsGetRecord(m_database,m_condition,m_record);
219 | return true;
220 | }
221 |
222 | bool TB_grade::end()
223 | {
224 | if(!KsLastRecord(m_database,m_condition))
225 | {
226 | return false;
227 | }
228 | KsGetRecord(m_database,m_condition,m_record);
229 | return true;
230 | }
231 |
232 | bool TB_grade::gotorow(int rowid)
233 | {
234 | if(!KsGotoRecord(m_database,0,rowid,m_condition))
235 | {
236 | return false;
237 | }
238 | KsGetRecord(m_database,m_condition,m_record);
239 | return true;
240 | }
241 |
242 | int TB_grade::recordrowid()
243 | {
244 | return KsGetRecordId(m_database,m_record);
245 | }
246 |
247 | bool TB_grade::dump(char *filename)
248 | {
249 | return KsDumpTable(m_database,0,filename);
250 | }
251 |
252 | bool TB_grade::SaveCsv(char *filename)
253 | {
254 | return KsWriteTableCsv(m_database,0,filename);
255 | }
256 |
257 | bool TB_grade::LoadCsv(char *filename)
258 | {
259 | return KsReadTableCsv(m_database,0,m_record,filename);
260 | }
261 |
262 | bool TB_grade::SaveTXT(char *filename)
263 | {
264 | return KsWriteTableTxt(m_database,0,filename);
265 | }
266 |
267 | bool TB_grade::LoadTXT(char *filename)
268 | {
269 | return KsReadTableTxt(m_database,0,m_record,filename);
270 | }
271 |
272 | bool TB_grade::SaveBinary(char *filename)
273 | {
274 | return KsWriteTableBinary(m_database,0,filename);
275 | }
276 |
277 | bool TB_grade::LoadBinary(char *filename)
278 | {
279 | return KsReadTableBinary(m_database,0,m_record,filename);
280 | }
281 |
282 | bool TB_grade::backup(char *filename)
283 | {
284 | return KsWriteDbTable(m_database,0,filename);
285 | }
286 |
287 | bool TB_grade::load(char *filename)
288 | {
289 | return KsReadDbTable(m_database,0,filename);
290 | }
291 |
292 | int TB_grade::get_id()
293 | {
294 | int fieldtype;
295 | int r;
296 |
297 | memcpy(&r,KsGetField(m_database,m_record,0,fieldtype),sizeof(int));
298 | return r;
299 | }
300 |
301 | bool TB_grade::set_value(int value)
302 | {
303 | return KsSetField(m_database,m_record,1,(char *)&value);
304 | }
305 |
306 | int TB_grade::get_value()
307 | {
308 | int fieldtype;
309 | int r;
310 |
311 | memcpy(&r,KsGetField(m_database,m_record,1,fieldtype),sizeof(int));
312 | return r;
313 | }
314 |
315 | bool TB_grade::find_by_pkey(int id,int op)
316 | {
317 | KsSetConditionIndex(m_condition,0);
318 | KsAddConditionIndexItem(m_condition,KSTYPE_INT4,4,(char *)&id);
319 | if (!KsFindRecord(m_database,0,m_condition,op))
320 | {
321 | return false;
322 | }
323 | KsGetRecord(m_database,m_condition,m_record);
324 | return true;
325 | }
326 |
327 | bool TB_grade::lists()
328 | {
329 | KsSetConditionIndex(m_condition,-1);
330 | if (!KsListRecord(m_database,0,m_condition))
331 | {
332 | return false;
333 | }
334 | KsGetRecord(m_database,m_condition,m_record);
335 | return true;
336 | }
337 |
338 | bool TB_grade::list_by_pkey()
339 | {
340 | KsSetConditionIndex(m_condition,0);
341 | if (!KsListRecord(m_database,0,m_condition))
342 | {
343 | return false;
344 | }
345 | KsGetRecord(m_database,m_condition,m_record);
346 | return true;
347 | }
348 |
349 |
--------------------------------------------------------------------------------
/ksmdb/samples/benchmark/perf.h:
--------------------------------------------------------------------------------
1 | #ifndef __perf_HH
2 | #define __perf_HH
3 | #include "cache.h"
4 | #include
5 | class DB_perf
6 | {
7 | private:
8 | bool m_inited;
9 | KsDbHandle m_database;
10 | public:
11 | DB_perf();
12 | virtual ~DB_perf(){};
13 | bool Create(char *path,char *name,size_t size);
14 | bool Open(char *path,char *name,int mode,int port,bool isolate, int reuse_shmmap, int shmrcset_mode=0);
15 | void UnLockDb();
16 | void SetErrorHandle(KsErrorHandle handle);
17 | int GetCols(KsRecordHandle handle);
18 | char *GetColName(KsRecordHandle handle,int col);
19 | int GetColType(KsRecordHandle handle,int col);
20 | int GetColSize(KsRecordHandle handle,int col);
21 | int GetColDecimal(KsRecordHandle handle,int col);
22 | char *GetColData(KsRecordHandle handle,int col);
23 | void GetMemoryInfo(size_t &size,size_t &inused);
24 | void Reset();
25 | bool Backup(char *filename);
26 | bool Load(char *filename);
27 | void BeginTransaction();
28 | void RollbackTransaction();
29 | void CommitTransaction();
30 | void GetLastError(int *errcode,char *errmsg);
31 | void Close();
32 | char *LibVersion();
33 | char *DbVersion();
34 | KsDbHandle GetDBHandle();
35 | };
36 |
37 | class TB_grade
38 | {
39 | private:
40 | KsDbHandle m_database;
41 | public:
42 | KsRecordHandle m_record;
43 | KsConditionHandle m_condition;
44 | public:
45 | TB_grade(KsDbHandle database);
46 | TB_grade(TB_grade &V);
47 | virtual ~TB_grade();
48 | bool newrecord();
49 | bool append(int id);
50 | bool erase();
51 | bool first();
52 | bool prev();
53 | bool next();
54 | bool end();
55 | bool gotorow(int rowid);
56 | int recordrowid();
57 | bool dump(char *filename="grade");
58 | bool SaveCsv(char *filename="grade.csv");
59 | bool LoadCsv(char *filename="grade.csv");
60 | bool SaveTXT(char *filename="grade.txt");
61 | bool LoadTXT(char *filename="grade.txt");
62 | bool SaveBinary(char *filename="grade.txt");
63 | bool LoadBinary(char *filename="grade.txt");
64 | bool backup(char *filename="grade");
65 | bool load(char *filename="grade");
66 | int get_id();
67 | bool set_value(int value);
68 | int get_value();
69 | bool find_by_pkey(int id,int op=EQ);
70 | bool lists();
71 | bool list_by_pkey();
72 | };
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/ksmdb/samples/benchmark/perf.ks:
--------------------------------------------------------------------------------
1 | declare database perf;
2 | class grade
3 | {
4 | int4 id;
5 | int4 value;
6 | unique tree pkey;
7 | };
8 |
--------------------------------------------------------------------------------
/ksmdb/samples/benchmark/perf.script:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/benchmark/perf.script
--------------------------------------------------------------------------------
/ksmdb/samples/benchmark/testperf.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/benchmark/testperf.cpp
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/build.sh:
--------------------------------------------------------------------------------
1 | ../../bin/linux/kstbcmp db_def.ks student
2 |
3 | make
4 |
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/db_def.ks:
--------------------------------------------------------------------------------
1 | declare database student;
2 | class grade
3 | {
4 | int4 id;
5 | string<50> name;
6 | string<10> classroom;
7 | double<0> math;
8 | double<0> Chinese;
9 | double<0> english;
10 | unique tree pkey;
11 | tree nameindex;
12 | tree classroom;
13 | tree nameclassroom;
14 | };
15 |
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/errhandler.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {6421F65F-8E9B-46DA-9EF7-BDF08566B26B}
15 | errhandler
16 | Win32Proj
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | v141
23 | Unicode
24 | true
25 |
26 |
27 | Application
28 | v141
29 | Unicode
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | <_ProjectFileVersion>15.0.28307.799
43 |
44 |
45 | $(SolutionDir)$(Configuration)\
46 | $(Configuration)\
47 | true
48 |
49 |
50 | $(SolutionDir)$(Configuration)\
51 | $(Configuration)\
52 | false
53 |
54 |
55 |
56 | Disabled
57 | ..\..\include;%(AdditionalIncludeDirectories)
58 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
59 | true
60 | EnableFastChecks
61 | MultiThreadedDebugDLL
62 |
63 | Level3
64 | EditAndContinue
65 |
66 |
67 | ksmdb.lib;%(AdditionalDependencies)
68 | $(SolutionDir)..\bin\errhandler.exe
69 | ..\..\lib\windows;%(AdditionalLibraryDirectories)
70 | true
71 | Console
72 | MachineX86
73 |
74 |
75 |
76 |
77 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
78 | MultiThreadedDLL
79 |
80 | Level3
81 | ProgramDatabase
82 | $(SolutionDir)\..\include
83 |
84 |
85 | true
86 | Console
87 | true
88 | true
89 | MachineX86
90 | $(SolutionDir)/../lib/windows/
91 | ksmdb32.lib;ws2_32.lib;%(AdditionalDependencies)
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/grade:
--------------------------------------------------------------------------------
1 | origin_index_name=pkey(id)
2 | origin_index_name=nameindex(name)
3 | origin_index_name=classroom(classroom)
4 | origin_index_name=nameclassroom(name,classroom)
5 | curent_index_name=pkey(id)
6 | curent_index_name=nameindex(name)
7 | curent_index_name=classroom(classroom)
8 | curent_index_name=nameclassroom(name,classroom)
9 | tablename=grade(id,name,classroom,math,Chinese,english)
10 |
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/grade.tb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/errhandler/grade.tb
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/makefile:
--------------------------------------------------------------------------------
1 | CXX = g++
2 | CXXFLAGS = -g
3 | LINK = $(CXX)
4 |
5 | INCLD = -I../../include
6 | LIBS = -L../../lib/linux -lksmdb -lm -lrt -lstdc++ -lpthread
7 |
8 | TARGET = errhandler
9 |
10 | OBJS = student.o test.o
11 |
12 | all:$(TARGET)
13 |
14 | errhandler:$(OBJS)
15 | $(LINK) -static -o errhandler $(OBJS) $(INCLD) $(LIBS)
16 | rm -rf *.o
17 |
18 | .cpp.o:
19 | $(CXX) $(CXXFLAGS) $(INCLD) -c $< -o $@
20 |
21 | clean:
22 | rm -f *.o
23 | rm -f errhandler
24 |
25 |
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/qzh:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/errhandler/qzh
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/student.cpp:
--------------------------------------------------------------------------------
1 | #include "student.h"
2 | DB_student::DB_student()
3 | {
4 | m_inited = false;
5 | m_database = NULL;
6 | }
7 |
8 | bool DB_student::Create(char *path,char *name,size_t size)
9 | {
10 | if(m_inited)
11 | {
12 | return true;
13 | }
14 | m_inited=true;
15 | if (KsCreateDb(&m_database,path,name,"20210423-10:49:59:000",size) == true)
16 | {
17 | KsAddTable(m_database,"grade");
18 | KsAddField(m_database,0,"id",KSTYPE_INT4,4,-1);
19 | KsAddField(m_database,0,"name",KSTYPE_STRING,51,-1);
20 | KsAddField(m_database,0,"classroom",KSTYPE_STRING,11,-1);
21 | KsAddField(m_database,0,"math",KSTYPE_DOUBLE,8,0);
22 | KsAddField(m_database,0,"Chinese",KSTYPE_DOUBLE,8,0);
23 | KsAddField(m_database,0,"english",KSTYPE_DOUBLE,8,0);
24 | KsAddIndex(m_database,0,"pkey",UNIQUE_INDEX);
25 | KsAddIndexField(m_database,0,0,0);
26 | KsAddIndex(m_database,0,"nameindex",NONUNIQUE_INDEX);
27 | KsAddIndexField(m_database,0,1,1);
28 | KsAddIndex(m_database,0,"classroom",NONUNIQUE_INDEX);
29 | KsAddIndexField(m_database,0,2,2);
30 | KsAddIndex(m_database,0,"nameclassroom",NONUNIQUE_INDEX);
31 | KsAddIndexField(m_database,0,3,1);
32 | KsAddIndexField(m_database,0,3,2);
33 | KsSaveDbInfo(m_database);
34 | }
35 | else
36 | {
37 | m_inited=false;
38 | return false;
39 | }
40 | KsLoadDb(m_database);
41 | return true;
42 | };
43 |
44 | bool DB_student::Open(char *path,char *name,int mode,int port,bool isolate,int reuse_shmmap, int shmrcset_mode)
45 | {
46 | if(m_inited)
47 | {
48 | return true;
49 | }
50 | m_inited=true;
51 | if (KsOpenDb(&m_database,path,name,"20210423-10:49:59:000",mode,port,isolate, reuse_shmmap, shmrcset_mode) == true)
52 | {
53 | KsLoadDbInfo(m_database);
54 | }
55 | else
56 | {
57 | m_inited=false;
58 | return false;
59 | }
60 | KsLoadDb(m_database);
61 | return true;
62 | };
63 |
64 | void DB_student::UnLockDb()
65 | {
66 | KsUnLockDb(m_database);
67 | }
68 |
69 | void DB_student::SetErrorHandle(KsErrorHandle handle)
70 | {
71 | KsSetErrorHandle(m_database,handle);
72 | }
73 |
74 | int DB_student::GetCols(KsRecordHandle handle)
75 | {
76 | return KsGetCols(m_database,handle);
77 | }
78 |
79 | char *DB_student::GetColName(KsRecordHandle handle,int col)
80 | {
81 | return KsGetColName(m_database,handle,col);
82 | }
83 |
84 | int DB_student::GetColType(KsRecordHandle handle,int col)
85 | {
86 | return KsGetColType(m_database,handle,col);
87 | }
88 |
89 | int DB_student::GetColSize(KsRecordHandle handle,int col)
90 | {
91 | return KsGetColSize(m_database,handle,col);
92 | }
93 |
94 | int DB_student::GetColDecimal(KsRecordHandle handle,int col)
95 | {
96 | return KsGetColDecimal(m_database,handle,col);
97 | }
98 |
99 | char *DB_student::GetColData(KsRecordHandle handle,int col)
100 | {
101 | return KsGetColData(m_database,handle,col);
102 | }
103 |
104 | void DB_student::GetMemoryInfo(size_t &size,size_t &inused)
105 | {
106 | KsMemoryInfo(m_database,&size,&inused);
107 | }
108 |
109 | void DB_student::Reset()
110 | {
111 | KsResetDb(m_database);
112 | }
113 |
114 | bool DB_student::Backup(char *filename)
115 | {
116 | return KsWriteDbFile(m_database,filename);
117 | }
118 |
119 | bool DB_student::Load(char *filename)
120 | {
121 | return KsReadDbFile(m_database,filename);
122 | }
123 |
124 | void DB_student::BeginTransaction()
125 | {
126 | KsBeginTransaction(m_database);
127 | }
128 |
129 | void DB_student::RollbackTransaction()
130 | {
131 | KsRollbackTransaction(m_database);
132 | }
133 |
134 | void DB_student::CommitTransaction()
135 | {
136 | KsCommitTransaction(m_database);
137 | }
138 |
139 | void DB_student::GetLastError(int *errcode,char *errmsg)
140 | {
141 | KsGetError(m_database,*errcode,errmsg);
142 | }
143 |
144 | void DB_student::Close()
145 | {
146 | KsDeleteDb(m_database);
147 | m_inited=false;
148 | }
149 |
150 | char* DB_student::LibVersion()
151 | {
152 | return KsGetLibVersion();
153 | }
154 |
155 | char* DB_student::DbVersion()
156 | {
157 | return KsGetDbVersion(m_database);
158 | }
159 |
160 | KsDbHandle DB_student::GetDBHandle()
161 | {
162 | return m_database;
163 | }
164 |
165 | TB_grade::TB_grade(KsDbHandle database)
166 | {
167 | m_database = database;
168 | KsCreateCondition(2,&m_condition);
169 | KsCreateRecord(&m_record);
170 | }
171 |
172 | TB_grade::TB_grade(TB_grade &V)
173 | {
174 | KsCreateCondition(2,&m_condition);
175 | KsCreateRecord(&m_record);
176 | KsDupCondition(V.m_condition,m_condition);
177 | KsDupRecord(V.m_record,m_record);
178 | }
179 |
180 | TB_grade::~TB_grade()
181 | {
182 | KsCloseCondition(m_condition);
183 | KsCloseRecord(m_database,m_record);
184 | }
185 |
186 | bool TB_grade::newrecord()
187 | {
188 | return KsNewRecord(m_database,0,m_record);
189 | }
190 |
191 | bool TB_grade::append(int id,char* name,char* classroom)
192 | {
193 | KsSetField(m_database,m_record,0,(char *)&id);
194 | KsSetField(m_database,m_record,1,(char *)name);
195 | KsSetField(m_database,m_record,2,(char *)classroom);
196 | return KsPutRecord(m_database,m_record);
197 | }
198 |
199 | bool TB_grade::erase()
200 | {
201 | KsDeleteRecord(m_database,m_record);
202 | return true;
203 | }
204 |
205 | bool TB_grade::first()
206 | {
207 | if(!KsFirstRecord(m_database,m_condition))
208 | {
209 | return false;
210 | }
211 | KsGetRecord(m_database,m_condition,m_record);
212 | return true;
213 | }
214 |
215 | bool TB_grade::prev()
216 | {
217 | if(!KsPrevRecord(m_database,m_condition))
218 | {
219 | return false;
220 | }
221 | KsGetRecord(m_database,m_condition,m_record);
222 | return true;
223 | }
224 |
225 | bool TB_grade::next()
226 | {
227 | if(!KsNextRecord(m_database,m_condition))
228 | {
229 | return false;
230 | }
231 | KsGetRecord(m_database,m_condition,m_record);
232 | return true;
233 | }
234 |
235 | bool TB_grade::end()
236 | {
237 | if(!KsLastRecord(m_database,m_condition))
238 | {
239 | return false;
240 | }
241 | KsGetRecord(m_database,m_condition,m_record);
242 | return true;
243 | }
244 |
245 | bool TB_grade::gotorow(int rowid)
246 | {
247 | if(!KsGotoRecord(m_database,0,rowid,m_condition))
248 | {
249 | return false;
250 | }
251 | KsGetRecord(m_database,m_condition,m_record);
252 | return true;
253 | }
254 |
255 | int TB_grade::recordrowid()
256 | {
257 | return KsGetRecordId(m_database,m_record);
258 | }
259 |
260 | bool TB_grade::dump(char *filename)
261 | {
262 | return KsDumpTable(m_database,0,filename);
263 | }
264 |
265 | bool TB_grade::SaveCsv(char *filename)
266 | {
267 | return KsWriteTableCsv(m_database,0,filename);
268 | }
269 |
270 | bool TB_grade::LoadCsv(char *filename)
271 | {
272 | return KsReadTableCsv(m_database,0,m_record,filename);
273 | }
274 |
275 | bool TB_grade::SaveTXT(char *filename)
276 | {
277 | return KsWriteTableTxt(m_database,0,filename);
278 | }
279 |
280 | bool TB_grade::LoadTXT(char *filename)
281 | {
282 | return KsReadTableTxt(m_database,0,m_record,filename);
283 | }
284 |
285 | bool TB_grade::SaveBinary(char *filename)
286 | {
287 | return KsWriteTableBinary(m_database,0,filename);
288 | }
289 |
290 | bool TB_grade::LoadBinary(char *filename)
291 | {
292 | return KsReadTableBinary(m_database,0,m_record,filename);
293 | }
294 |
295 | bool TB_grade::backup(char *filename)
296 | {
297 | return KsWriteDbTable(m_database,0,filename);
298 | }
299 |
300 | bool TB_grade::load(char *filename)
301 | {
302 | return KsReadDbTable(m_database,0,filename);
303 | }
304 |
305 | int TB_grade::get_id()
306 | {
307 | int fieldtype;
308 | int r;
309 |
310 | memcpy(&r,KsGetField(m_database,m_record,0,fieldtype),sizeof(int));
311 | return r;
312 | }
313 |
314 | char* TB_grade::get_name()
315 | {
316 | int fieldtype;
317 |
318 | return (char *)KsGetField(m_database,m_record,1,fieldtype);
319 | }
320 |
321 | char* TB_grade::get_classroom()
322 | {
323 | int fieldtype;
324 |
325 | return (char *)KsGetField(m_database,m_record,2,fieldtype);
326 | }
327 |
328 | bool TB_grade::set_math(double value)
329 | {
330 | return KsSetField(m_database,m_record,3,(char *)&value);
331 | }
332 |
333 | double TB_grade::get_math()
334 | {
335 | int fieldtype;
336 | double r;
337 |
338 | memcpy(&r,KsGetField(m_database,m_record,3,fieldtype),sizeof(double));
339 | return r;
340 | }
341 |
342 | bool TB_grade::set_Chinese(double value)
343 | {
344 | return KsSetField(m_database,m_record,4,(char *)&value);
345 | }
346 |
347 | double TB_grade::get_Chinese()
348 | {
349 | int fieldtype;
350 | double r;
351 |
352 | memcpy(&r,KsGetField(m_database,m_record,4,fieldtype),sizeof(double));
353 | return r;
354 | }
355 |
356 | bool TB_grade::set_english(double value)
357 | {
358 | return KsSetField(m_database,m_record,5,(char *)&value);
359 | }
360 |
361 | double TB_grade::get_english()
362 | {
363 | int fieldtype;
364 | double r;
365 |
366 | memcpy(&r,KsGetField(m_database,m_record,5,fieldtype),sizeof(double));
367 | return r;
368 | }
369 |
370 | bool TB_grade::find_by_pkey(int id,int op)
371 | {
372 | KsSetConditionIndex(m_condition,0);
373 | KsAddConditionIndexItem(m_condition,KSTYPE_INT4,4,(char *)&id);
374 | if (!KsFindRecord(m_database,0,m_condition,op))
375 | {
376 | return false;
377 | }
378 | KsGetRecord(m_database,m_condition,m_record);
379 | return true;
380 | }
381 |
382 | bool TB_grade::find_by_nameindex(char* name,int op)
383 | {
384 | KsSetConditionIndex(m_condition,1);
385 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,51,(char *)name);
386 | if (!KsFindRecord(m_database,0,m_condition,op))
387 | {
388 | return false;
389 | }
390 | KsGetRecord(m_database,m_condition,m_record);
391 | return true;
392 | }
393 |
394 | bool TB_grade::find_by_classroom(char* classroom,int op)
395 | {
396 | KsSetConditionIndex(m_condition,2);
397 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,11,(char *)classroom);
398 | if (!KsFindRecord(m_database,0,m_condition,op))
399 | {
400 | return false;
401 | }
402 | KsGetRecord(m_database,m_condition,m_record);
403 | return true;
404 | }
405 |
406 | bool TB_grade::find_by_nameclassroom(char* name,char* classroom,int op)
407 | {
408 | KsSetConditionIndex(m_condition,3);
409 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,51,(char *)name);
410 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,11,(char *)classroom);
411 | if (!KsFindRecord(m_database,0,m_condition,op))
412 | {
413 | return false;
414 | }
415 | KsGetRecord(m_database,m_condition,m_record);
416 | return true;
417 | }
418 |
419 | bool TB_grade::lists()
420 | {
421 | KsSetConditionIndex(m_condition,-1);
422 | if (!KsListRecord(m_database,0,m_condition))
423 | {
424 | return false;
425 | }
426 | KsGetRecord(m_database,m_condition,m_record);
427 | return true;
428 | }
429 |
430 | bool TB_grade::list_by_pkey()
431 | {
432 | KsSetConditionIndex(m_condition,0);
433 | if (!KsListRecord(m_database,0,m_condition))
434 | {
435 | return false;
436 | }
437 | KsGetRecord(m_database,m_condition,m_record);
438 | return true;
439 | }
440 |
441 | bool TB_grade::list_by_nameindex()
442 | {
443 | KsSetConditionIndex(m_condition,1);
444 | if (!KsListRecord(m_database,0,m_condition))
445 | {
446 | return false;
447 | }
448 | KsGetRecord(m_database,m_condition,m_record);
449 | return true;
450 | }
451 |
452 | bool TB_grade::list_by_classroom()
453 | {
454 | KsSetConditionIndex(m_condition,2);
455 | if (!KsListRecord(m_database,0,m_condition))
456 | {
457 | return false;
458 | }
459 | KsGetRecord(m_database,m_condition,m_record);
460 | return true;
461 | }
462 |
463 | bool TB_grade::list_by_nameclassroom()
464 | {
465 | KsSetConditionIndex(m_condition,3);
466 | if (!KsListRecord(m_database,0,m_condition))
467 | {
468 | return false;
469 | }
470 | KsGetRecord(m_database,m_condition,m_record);
471 | return true;
472 | }
473 |
474 |
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/student.h:
--------------------------------------------------------------------------------
1 | #ifndef __student_HH
2 | #define __student_HH
3 | #include "cache.h"
4 | #include
5 | class DB_student
6 | {
7 | private:
8 | bool m_inited;
9 | KsDbHandle m_database;
10 | public:
11 | DB_student();
12 | virtual ~DB_student(){};
13 | bool Create(char *path,char *name,size_t size);
14 | bool Open(char *path,char *name,int mode,int port,bool isolate, int reuse_shmmap, int shmrcset_mode=0);
15 | void UnLockDb();
16 | void SetErrorHandle(KsErrorHandle handle);
17 | int GetCols(KsRecordHandle handle);
18 | char *GetColName(KsRecordHandle handle,int col);
19 | int GetColType(KsRecordHandle handle,int col);
20 | int GetColSize(KsRecordHandle handle,int col);
21 | int GetColDecimal(KsRecordHandle handle,int col);
22 | char *GetColData(KsRecordHandle handle,int col);
23 | void GetMemoryInfo(size_t &size,size_t &inused);
24 | void Reset();
25 | bool Backup(char *filename);
26 | bool Load(char *filename);
27 | void BeginTransaction();
28 | void RollbackTransaction();
29 | void CommitTransaction();
30 | void GetLastError(int *errcode,char *errmsg);
31 | void Close();
32 | char *LibVersion();
33 | char *DbVersion();
34 | KsDbHandle GetDBHandle();
35 | };
36 |
37 | class TB_grade
38 | {
39 | private:
40 | KsDbHandle m_database;
41 | public:
42 | KsRecordHandle m_record;
43 | KsConditionHandle m_condition;
44 | public:
45 | TB_grade(KsDbHandle database);
46 | TB_grade(TB_grade &V);
47 | virtual ~TB_grade();
48 | bool newrecord();
49 | bool append(int id,char* name,char* classroom);
50 | bool erase();
51 | bool first();
52 | bool prev();
53 | bool next();
54 | bool end();
55 | bool gotorow(int rowid);
56 | int recordrowid();
57 | bool dump(char *filename="grade");
58 | bool SaveCsv(char *filename="grade.csv");
59 | bool LoadCsv(char *filename="grade.csv");
60 | bool SaveTXT(char *filename="grade.txt");
61 | bool LoadTXT(char *filename="grade.txt");
62 | bool SaveBinary(char *filename="grade.txt");
63 | bool LoadBinary(char *filename="grade.txt");
64 | bool backup(char *filename="grade");
65 | bool load(char *filename="grade");
66 | int get_id();
67 | char* get_name();
68 | char* get_classroom();
69 | bool set_math(double value);
70 | double get_math();
71 | bool set_Chinese(double value);
72 | double get_Chinese();
73 | bool set_english(double value);
74 | double get_english();
75 | bool find_by_pkey(int id,int op=EQ);
76 | bool find_by_nameindex(char* name,int op=EQ);
77 | bool find_by_classroom(char* classroom,int op=EQ);
78 | bool find_by_nameclassroom(char* name,char* classroom,int op=EQ);
79 | bool lists();
80 | bool list_by_pkey();
81 | bool list_by_nameindex();
82 | bool list_by_classroom();
83 | bool list_by_nameclassroom();
84 | };
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/student.script:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/errhandler/student.script
--------------------------------------------------------------------------------
/ksmdb/samples/errhandler/test.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/errhandler/test.cpp
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/build.sh:
--------------------------------------------------------------------------------
1 | ../../bin/linux/kstbcmp db_def.ks student
2 |
3 | make
4 |
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/db_def.ks:
--------------------------------------------------------------------------------
1 | declare database student;
2 | class grade
3 | {
4 | int4 id;
5 | string<50> name;
6 | string<10> classroom;
7 | double<0> math;
8 | double<0> Chinese;
9 | double<0> english;
10 | unique tree pkey;
11 | tree nameindex;
12 | tree classroom;
13 | tree nameclassroom;
14 | };
15 |
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/grade:
--------------------------------------------------------------------------------
1 | origin_index_name=pkey(id)
2 | origin_index_name=nameindex(name)
3 | origin_index_name=classroom(classroom)
4 | origin_index_name=nameclassroom(name,classroom)
5 | curent_index_name=pkey(id)
6 | curent_index_name=nameindex(name)
7 | curent_index_name=classroom(classroom)
8 | curent_index_name=nameclassroom(name,classroom)
9 | tablename=grade(id,name,classroom,math,Chinese,english)
10 |
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/grade.tb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/multithread/grade.tb
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/makefile:
--------------------------------------------------------------------------------
1 | CXX = g++
2 | CXXFLAGS = -g
3 | LINK = $(CXX)
4 |
5 | INCLD = -I../../include
6 | LIBS = -L../../lib/linux -lksmdb -lm -lrt -lstdc++ -lpthread
7 |
8 | TARGET = multithread
9 |
10 | OBJS = student.o test.o tools.o
11 |
12 | all:$(TARGET)
13 |
14 | multithread:$(OBJS)
15 | $(LINK) -static -o multithread $(OBJS) $(INCLD) $(LIBS)
16 | rm -rf *.o
17 |
18 | .cpp.o:
19 | $(CXX) $(CXXFLAGS) $(INCLD) -c $< -o $@
20 |
21 | clean:
22 | rm -f *.o
23 | rm -f multithread
24 |
25 |
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/multithread.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {5F19BA37-E920-4CA5-81D3-8DDF251EF72C}
15 | multithread
16 | Win32Proj
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | v141
23 | Unicode
24 | true
25 |
26 |
27 | Application
28 | v141
29 | Unicode
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | <_ProjectFileVersion>15.0.28307.799
43 |
44 |
45 | $(SolutionDir)$(Configuration)\
46 | $(Configuration)\
47 | true
48 |
49 |
50 | $(SolutionDir)$(Configuration)\
51 | $(Configuration)\
52 | false
53 |
54 |
55 |
56 | Disabled
57 | ..\..\include;%(AdditionalIncludeDirectories)
58 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
59 | true
60 | EnableFastChecks
61 | MultiThreadedDebugDLL
62 |
63 | Level3
64 | EditAndContinue
65 |
66 |
67 | ksmdb.lib;%(AdditionalDependencies)
68 | $(SolutionDir)..\bin\multithread.exe
69 | ..\..\lib\windows;%(AdditionalLibraryDirectories)
70 | true
71 | Console
72 | MachineX86
73 |
74 |
75 |
76 |
77 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
78 | MultiThreadedDLL
79 |
80 | Level3
81 | ProgramDatabase
82 | $(SolutionDir)\..\include
83 |
84 |
85 | true
86 | Console
87 | true
88 | true
89 | MachineX86
90 | $(SolutionDir)/../lib/windows/
91 | ksmdb32.lib;ws2_32.lib;%(AdditionalDependencies)
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/student.cpp:
--------------------------------------------------------------------------------
1 | #include "student.h"
2 | DB_student::DB_student()
3 | {
4 | m_inited = false;
5 | m_database = NULL;
6 | }
7 |
8 | bool DB_student::Create(char *path,char *name,size_t size)
9 | {
10 | if(m_inited)
11 | {
12 | return true;
13 | }
14 | m_inited=true;
15 | if (KsCreateDb(&m_database,path,name,"20210423-10:48:42:000",size) == true)
16 | {
17 | KsAddTable(m_database,"grade");
18 | KsAddField(m_database,0,"id",KSTYPE_INT4,4,-1);
19 | KsAddField(m_database,0,"name",KSTYPE_STRING,51,-1);
20 | KsAddField(m_database,0,"classroom",KSTYPE_STRING,11,-1);
21 | KsAddField(m_database,0,"math",KSTYPE_DOUBLE,8,0);
22 | KsAddField(m_database,0,"Chinese",KSTYPE_DOUBLE,8,0);
23 | KsAddField(m_database,0,"english",KSTYPE_DOUBLE,8,0);
24 | KsAddIndex(m_database,0,"pkey",UNIQUE_INDEX);
25 | KsAddIndexField(m_database,0,0,0);
26 | KsAddIndex(m_database,0,"nameindex",NONUNIQUE_INDEX);
27 | KsAddIndexField(m_database,0,1,1);
28 | KsAddIndex(m_database,0,"classroom",NONUNIQUE_INDEX);
29 | KsAddIndexField(m_database,0,2,2);
30 | KsAddIndex(m_database,0,"nameclassroom",NONUNIQUE_INDEX);
31 | KsAddIndexField(m_database,0,3,1);
32 | KsAddIndexField(m_database,0,3,2);
33 | KsSaveDbInfo(m_database);
34 | }
35 | else
36 | {
37 | m_inited=false;
38 | return false;
39 | }
40 | KsLoadDb(m_database);
41 | return true;
42 | };
43 |
44 | bool DB_student::Open(char *path,char *name,int mode,int port,bool isolate,int reuse_shmmap, int shmrcset_mode)
45 | {
46 | if(m_inited)
47 | {
48 | return true;
49 | }
50 | m_inited=true;
51 | if (KsOpenDb(&m_database,path,name,"20210423-10:48:42:000",mode,port,isolate, reuse_shmmap, shmrcset_mode) == true)
52 | {
53 | KsLoadDbInfo(m_database);
54 | }
55 | else
56 | {
57 | m_inited=false;
58 | return false;
59 | }
60 | KsLoadDb(m_database);
61 | return true;
62 | };
63 |
64 | void DB_student::UnLockDb()
65 | {
66 | KsUnLockDb(m_database);
67 | }
68 |
69 | void DB_student::SetErrorHandle(KsErrorHandle handle)
70 | {
71 | KsSetErrorHandle(m_database,handle);
72 | }
73 |
74 | int DB_student::GetCols(KsRecordHandle handle)
75 | {
76 | return KsGetCols(m_database,handle);
77 | }
78 |
79 | char *DB_student::GetColName(KsRecordHandle handle,int col)
80 | {
81 | return KsGetColName(m_database,handle,col);
82 | }
83 |
84 | int DB_student::GetColType(KsRecordHandle handle,int col)
85 | {
86 | return KsGetColType(m_database,handle,col);
87 | }
88 |
89 | int DB_student::GetColSize(KsRecordHandle handle,int col)
90 | {
91 | return KsGetColSize(m_database,handle,col);
92 | }
93 |
94 | int DB_student::GetColDecimal(KsRecordHandle handle,int col)
95 | {
96 | return KsGetColDecimal(m_database,handle,col);
97 | }
98 |
99 | char *DB_student::GetColData(KsRecordHandle handle,int col)
100 | {
101 | return KsGetColData(m_database,handle,col);
102 | }
103 |
104 | void DB_student::GetMemoryInfo(size_t &size,size_t &inused)
105 | {
106 | KsMemoryInfo(m_database,&size,&inused);
107 | }
108 |
109 | void DB_student::Reset()
110 | {
111 | KsResetDb(m_database);
112 | }
113 |
114 | bool DB_student::Backup(char *filename)
115 | {
116 | return KsWriteDbFile(m_database,filename);
117 | }
118 |
119 | bool DB_student::Load(char *filename)
120 | {
121 | return KsReadDbFile(m_database,filename);
122 | }
123 |
124 | void DB_student::BeginTransaction()
125 | {
126 | KsBeginTransaction(m_database);
127 | }
128 |
129 | void DB_student::RollbackTransaction()
130 | {
131 | KsRollbackTransaction(m_database);
132 | }
133 |
134 | void DB_student::CommitTransaction()
135 | {
136 | KsCommitTransaction(m_database);
137 | }
138 |
139 | void DB_student::GetLastError(int *errcode,char *errmsg)
140 | {
141 | KsGetError(m_database,*errcode,errmsg);
142 | }
143 |
144 | void DB_student::Close()
145 | {
146 | KsDeleteDb(m_database);
147 | m_inited=false;
148 | }
149 |
150 | char* DB_student::LibVersion()
151 | {
152 | return KsGetLibVersion();
153 | }
154 |
155 | char* DB_student::DbVersion()
156 | {
157 | return KsGetDbVersion(m_database);
158 | }
159 |
160 | KsDbHandle DB_student::GetDBHandle()
161 | {
162 | return m_database;
163 | }
164 |
165 | TB_grade::TB_grade(KsDbHandle database)
166 | {
167 | m_database = database;
168 | KsCreateCondition(2,&m_condition);
169 | KsCreateRecord(&m_record);
170 | }
171 |
172 | TB_grade::TB_grade(TB_grade &V)
173 | {
174 | KsCreateCondition(2,&m_condition);
175 | KsCreateRecord(&m_record);
176 | KsDupCondition(V.m_condition,m_condition);
177 | KsDupRecord(V.m_record,m_record);
178 | }
179 |
180 | TB_grade::~TB_grade()
181 | {
182 | KsCloseCondition(m_condition);
183 | KsCloseRecord(m_database,m_record);
184 | }
185 |
186 | bool TB_grade::newrecord()
187 | {
188 | return KsNewRecord(m_database,0,m_record);
189 | }
190 |
191 | bool TB_grade::append(int id,char* name,char* classroom)
192 | {
193 | KsSetField(m_database,m_record,0,(char *)&id);
194 | KsSetField(m_database,m_record,1,(char *)name);
195 | KsSetField(m_database,m_record,2,(char *)classroom);
196 | return KsPutRecord(m_database,m_record);
197 | }
198 |
199 | bool TB_grade::erase()
200 | {
201 | KsDeleteRecord(m_database,m_record);
202 | return true;
203 | }
204 |
205 | bool TB_grade::first()
206 | {
207 | if(!KsFirstRecord(m_database,m_condition))
208 | {
209 | return false;
210 | }
211 | KsGetRecord(m_database,m_condition,m_record);
212 | return true;
213 | }
214 |
215 | bool TB_grade::prev()
216 | {
217 | if(!KsPrevRecord(m_database,m_condition))
218 | {
219 | return false;
220 | }
221 | KsGetRecord(m_database,m_condition,m_record);
222 | return true;
223 | }
224 |
225 | bool TB_grade::next()
226 | {
227 | if(!KsNextRecord(m_database,m_condition))
228 | {
229 | return false;
230 | }
231 | KsGetRecord(m_database,m_condition,m_record);
232 | return true;
233 | }
234 |
235 | bool TB_grade::end()
236 | {
237 | if(!KsLastRecord(m_database,m_condition))
238 | {
239 | return false;
240 | }
241 | KsGetRecord(m_database,m_condition,m_record);
242 | return true;
243 | }
244 |
245 | bool TB_grade::gotorow(int rowid)
246 | {
247 | if(!KsGotoRecord(m_database,0,rowid,m_condition))
248 | {
249 | return false;
250 | }
251 | KsGetRecord(m_database,m_condition,m_record);
252 | return true;
253 | }
254 |
255 | int TB_grade::recordrowid()
256 | {
257 | return KsGetRecordId(m_database,m_record);
258 | }
259 |
260 | bool TB_grade::dump(char *filename)
261 | {
262 | return KsDumpTable(m_database,0,filename);
263 | }
264 |
265 | bool TB_grade::SaveCsv(char *filename)
266 | {
267 | return KsWriteTableCsv(m_database,0,filename);
268 | }
269 |
270 | bool TB_grade::LoadCsv(char *filename)
271 | {
272 | return KsReadTableCsv(m_database,0,m_record,filename);
273 | }
274 |
275 | bool TB_grade::SaveTXT(char *filename)
276 | {
277 | return KsWriteTableTxt(m_database,0,filename);
278 | }
279 |
280 | bool TB_grade::LoadTXT(char *filename)
281 | {
282 | return KsReadTableTxt(m_database,0,m_record,filename);
283 | }
284 |
285 | bool TB_grade::SaveBinary(char *filename)
286 | {
287 | return KsWriteTableBinary(m_database,0,filename);
288 | }
289 |
290 | bool TB_grade::LoadBinary(char *filename)
291 | {
292 | return KsReadTableBinary(m_database,0,m_record,filename);
293 | }
294 |
295 | bool TB_grade::backup(char *filename)
296 | {
297 | return KsWriteDbTable(m_database,0,filename);
298 | }
299 |
300 | bool TB_grade::load(char *filename)
301 | {
302 | return KsReadDbTable(m_database,0,filename);
303 | }
304 |
305 | int TB_grade::get_id()
306 | {
307 | int fieldtype;
308 | int r;
309 |
310 | memcpy(&r,KsGetField(m_database,m_record,0,fieldtype),sizeof(int));
311 | return r;
312 | }
313 |
314 | char* TB_grade::get_name()
315 | {
316 | int fieldtype;
317 |
318 | return (char *)KsGetField(m_database,m_record,1,fieldtype);
319 | }
320 |
321 | char* TB_grade::get_classroom()
322 | {
323 | int fieldtype;
324 |
325 | return (char *)KsGetField(m_database,m_record,2,fieldtype);
326 | }
327 |
328 | bool TB_grade::set_math(double value)
329 | {
330 | return KsSetField(m_database,m_record,3,(char *)&value);
331 | }
332 |
333 | double TB_grade::get_math()
334 | {
335 | int fieldtype;
336 | double r;
337 |
338 | memcpy(&r,KsGetField(m_database,m_record,3,fieldtype),sizeof(double));
339 | return r;
340 | }
341 |
342 | bool TB_grade::set_Chinese(double value)
343 | {
344 | return KsSetField(m_database,m_record,4,(char *)&value);
345 | }
346 |
347 | double TB_grade::get_Chinese()
348 | {
349 | int fieldtype;
350 | double r;
351 |
352 | memcpy(&r,KsGetField(m_database,m_record,4,fieldtype),sizeof(double));
353 | return r;
354 | }
355 |
356 | bool TB_grade::set_english(double value)
357 | {
358 | return KsSetField(m_database,m_record,5,(char *)&value);
359 | }
360 |
361 | double TB_grade::get_english()
362 | {
363 | int fieldtype;
364 | double r;
365 |
366 | memcpy(&r,KsGetField(m_database,m_record,5,fieldtype),sizeof(double));
367 | return r;
368 | }
369 |
370 | bool TB_grade::find_by_pkey(int id,int op)
371 | {
372 | KsSetConditionIndex(m_condition,0);
373 | KsAddConditionIndexItem(m_condition,KSTYPE_INT4,4,(char *)&id);
374 | if (!KsFindRecord(m_database,0,m_condition,op))
375 | {
376 | return false;
377 | }
378 | KsGetRecord(m_database,m_condition,m_record);
379 | return true;
380 | }
381 |
382 | bool TB_grade::find_by_nameindex(char* name,int op)
383 | {
384 | KsSetConditionIndex(m_condition,1);
385 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,51,(char *)name);
386 | if (!KsFindRecord(m_database,0,m_condition,op))
387 | {
388 | return false;
389 | }
390 | KsGetRecord(m_database,m_condition,m_record);
391 | return true;
392 | }
393 |
394 | bool TB_grade::find_by_classroom(char* classroom,int op)
395 | {
396 | KsSetConditionIndex(m_condition,2);
397 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,11,(char *)classroom);
398 | if (!KsFindRecord(m_database,0,m_condition,op))
399 | {
400 | return false;
401 | }
402 | KsGetRecord(m_database,m_condition,m_record);
403 | return true;
404 | }
405 |
406 | bool TB_grade::find_by_nameclassroom(char* name,char* classroom,int op)
407 | {
408 | KsSetConditionIndex(m_condition,3);
409 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,51,(char *)name);
410 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,11,(char *)classroom);
411 | if (!KsFindRecord(m_database,0,m_condition,op))
412 | {
413 | return false;
414 | }
415 | KsGetRecord(m_database,m_condition,m_record);
416 | return true;
417 | }
418 |
419 | bool TB_grade::lists()
420 | {
421 | KsSetConditionIndex(m_condition,-1);
422 | if (!KsListRecord(m_database,0,m_condition))
423 | {
424 | return false;
425 | }
426 | KsGetRecord(m_database,m_condition,m_record);
427 | return true;
428 | }
429 |
430 | bool TB_grade::list_by_pkey()
431 | {
432 | KsSetConditionIndex(m_condition,0);
433 | if (!KsListRecord(m_database,0,m_condition))
434 | {
435 | return false;
436 | }
437 | KsGetRecord(m_database,m_condition,m_record);
438 | return true;
439 | }
440 |
441 | bool TB_grade::list_by_nameindex()
442 | {
443 | KsSetConditionIndex(m_condition,1);
444 | if (!KsListRecord(m_database,0,m_condition))
445 | {
446 | return false;
447 | }
448 | KsGetRecord(m_database,m_condition,m_record);
449 | return true;
450 | }
451 |
452 | bool TB_grade::list_by_classroom()
453 | {
454 | KsSetConditionIndex(m_condition,2);
455 | if (!KsListRecord(m_database,0,m_condition))
456 | {
457 | return false;
458 | }
459 | KsGetRecord(m_database,m_condition,m_record);
460 | return true;
461 | }
462 |
463 | bool TB_grade::list_by_nameclassroom()
464 | {
465 | KsSetConditionIndex(m_condition,3);
466 | if (!KsListRecord(m_database,0,m_condition))
467 | {
468 | return false;
469 | }
470 | KsGetRecord(m_database,m_condition,m_record);
471 | return true;
472 | }
473 |
474 |
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/student.h:
--------------------------------------------------------------------------------
1 | #ifndef __student_HH
2 | #define __student_HH
3 | #include "cache.h"
4 | #include
5 | class DB_student
6 | {
7 | private:
8 | bool m_inited;
9 | KsDbHandle m_database;
10 | public:
11 | DB_student();
12 | virtual ~DB_student(){};
13 | bool Create(char *path,char *name,size_t size);
14 | bool Open(char *path,char *name,int mode,int port,bool isolate, int reuse_shmmap, int shmrcset_mode=0);
15 | void UnLockDb();
16 | void SetErrorHandle(KsErrorHandle handle);
17 | int GetCols(KsRecordHandle handle);
18 | char *GetColName(KsRecordHandle handle,int col);
19 | int GetColType(KsRecordHandle handle,int col);
20 | int GetColSize(KsRecordHandle handle,int col);
21 | int GetColDecimal(KsRecordHandle handle,int col);
22 | char *GetColData(KsRecordHandle handle,int col);
23 | void GetMemoryInfo(size_t &size,size_t &inused);
24 | void Reset();
25 | bool Backup(char *filename);
26 | bool Load(char *filename);
27 | void BeginTransaction();
28 | void RollbackTransaction();
29 | void CommitTransaction();
30 | void GetLastError(int *errcode,char *errmsg);
31 | void Close();
32 | char *LibVersion();
33 | char *DbVersion();
34 | KsDbHandle GetDBHandle();
35 | };
36 |
37 | class TB_grade
38 | {
39 | private:
40 | KsDbHandle m_database;
41 | public:
42 | KsRecordHandle m_record;
43 | KsConditionHandle m_condition;
44 | public:
45 | TB_grade(KsDbHandle database);
46 | TB_grade(TB_grade &V);
47 | virtual ~TB_grade();
48 | bool newrecord();
49 | bool append(int id,char* name,char* classroom);
50 | bool erase();
51 | bool first();
52 | bool prev();
53 | bool next();
54 | bool end();
55 | bool gotorow(int rowid);
56 | int recordrowid();
57 | bool dump(char *filename="grade");
58 | bool SaveCsv(char *filename="grade.csv");
59 | bool LoadCsv(char *filename="grade.csv");
60 | bool SaveTXT(char *filename="grade.txt");
61 | bool LoadTXT(char *filename="grade.txt");
62 | bool SaveBinary(char *filename="grade.txt");
63 | bool LoadBinary(char *filename="grade.txt");
64 | bool backup(char *filename="grade");
65 | bool load(char *filename="grade");
66 | int get_id();
67 | char* get_name();
68 | char* get_classroom();
69 | bool set_math(double value);
70 | double get_math();
71 | bool set_Chinese(double value);
72 | double get_Chinese();
73 | bool set_english(double value);
74 | double get_english();
75 | bool find_by_pkey(int id,int op=EQ);
76 | bool find_by_nameindex(char* name,int op=EQ);
77 | bool find_by_classroom(char* classroom,int op=EQ);
78 | bool find_by_nameclassroom(char* name,char* classroom,int op=EQ);
79 | bool lists();
80 | bool list_by_pkey();
81 | bool list_by_nameindex();
82 | bool list_by_classroom();
83 | bool list_by_nameclassroom();
84 | };
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/student.script:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/multithread/student.script
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/studentdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/multithread/studentdb
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/test.cpp:
--------------------------------------------------------------------------------
1 | #include "student.h"
2 | #include "tools.h"
3 | #include
4 | #if defined(WIN32)
5 | #include
6 | #endif
7 |
8 |
9 | bool myerrhandle(int errcode,char *errmsg)
10 | {
11 | printf("my errhandle:errcode=%d,errmsg=%s\n",errcode,errmsg);
12 | return true;
13 | }
14 |
15 |
16 |
17 | #ifdef WIN32
18 | unsigned int _stdcall
19 | #else
20 | void *
21 | #endif
22 | wthread(void *arg)
23 | {
24 |
25 | printf("readwrite thread start.\n");
26 |
27 | int errcode;
28 | char errmsg[300];
29 |
30 | char name[20]={0};
31 | char room[20]={0};
32 |
33 | DB_student studentdb;
34 |
35 | if (studentdb.Open(".","studentdb",READWRITE,5000,false,1) == false)
36 | {
37 | studentdb.GetLastError(&errcode,errmsg);
38 | printf("errcode=%d,errmsg=%s\n",errcode,errmsg);
39 | return 0;
40 | }
41 |
42 | studentdb.UnLockDb();
43 | studentdb.SetErrorHandle(myerrhandle);
44 |
45 | TB_grade grade(studentdb.GetDBHandle());
46 |
47 | studentdb.BeginTransaction();
48 |
49 | for (int i=0; i<1000; i++)
50 | {
51 | grade.newrecord();
52 | grade.set_math(i);
53 | grade.set_Chinese(i);
54 | grade.set_english(i);
55 | sprintf(name,"%d",i % 10);
56 | sprintf(room,"%d",i % 10);
57 | grade.append(i,name,room);
58 | }
59 | studentdb.CommitTransaction();
60 |
61 | studentdb.Close();
62 |
63 | return 0;
64 |
65 | }
66 |
67 |
68 |
69 | #ifdef WIN32
70 | unsigned int _stdcall
71 | #else
72 | void *
73 | #endif
74 | rthread(void *arg)
75 | {
76 |
77 | printf("readolny thread start.\n");
78 |
79 | //wait for data insert.
80 | printf("press any key to read data...\n");
81 | getchar();
82 |
83 | Sleep(1000);
84 |
85 | int errcode;
86 | char errmsg[300];
87 |
88 | DB_student studentdb;
89 |
90 | if (studentdb.Open(".","studentdb",READONLY,5000,false,1) == false)
91 | {
92 | studentdb.GetLastError(&errcode,errmsg);
93 | printf("errcode=%d,errmsg=%s\n",errcode,errmsg);
94 | return 0;
95 | }
96 |
97 | studentdb.UnLockDb();
98 | studentdb.SetErrorHandle(myerrhandle);
99 |
100 | TB_grade grade(studentdb.GetDBHandle());
101 |
102 | int i = 1;
103 | while (i<1000)
104 | {
105 |
106 | studentdb.BeginTransaction();
107 | if (!grade.find_by_pkey(i))
108 | {
109 | studentdb.CommitTransaction();
110 | continue;;
111 | }
112 | printf("FindById: id=%d,name=%s,classroom=%s,math=%4.1f,chinese=%4.1f,english=%4.1f\n",
113 | grade.get_id(),grade.get_name(),grade.get_classroom(),
114 | grade.get_math(),grade.get_Chinese(),grade.get_english());
115 |
116 | studentdb.CommitTransaction();
117 |
118 | i++;
119 |
120 | }
121 |
122 | studentdb.Close();
123 |
124 | return 0;
125 |
126 | }
127 |
128 |
129 |
130 | int main(int argc,char **argv)
131 | {
132 | DB_student studentdb;
133 | size_t size,inused;
134 | int errcode;
135 |
136 | char errmsg[300];
137 |
138 |
139 |
140 | if (studentdb.Create(".","studentdb",200000000) == false)
141 | {
142 | studentdb.GetLastError(&errcode,errmsg);
143 | printf("errcode=%d,errmsg=%s\n",errcode,errmsg);
144 | return 0;
145 | }
146 | studentdb.UnLockDb();
147 | studentdb.SetErrorHandle(myerrhandle);
148 |
149 | printf("database is created.\n");
150 |
151 | THREAD_HANDLE t_handle_w;
152 | create_thread(&t_handle_w, wthread, NULL);
153 |
154 | THREAD_HANDLE t_handle_r;
155 | create_thread(&t_handle_r, rthread, NULL);
156 |
157 | join_thread(t_handle_w);
158 | join_thread(t_handle_r);
159 |
160 |
161 | studentdb.GetMemoryInfo(size,inused);
162 | printf("size=%d,inused=%d\n",size,inused);
163 | studentdb.Close();
164 | printf("database is closed.\n");
165 | printf("press any key to quit...\n");
166 |
167 | getc(stdin);
168 | return 0;
169 | }
170 |
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/tools.c:
--------------------------------------------------------------------------------
1 | #include "tools.h"
2 |
3 |
4 | /*
5 | * thread functions.
6 | */
7 |
8 | int create_thread(THREAD_HANDLE *thread_id_ptr, ThreadProc thread_entry, void *thread_arg)
9 | {
10 | #ifdef WIN32
11 | // *thread_id_ptr = (HANDLE)_beginthread(thread_entry,0, thread_arg);
12 | *thread_id_ptr = (HANDLE)_beginthreadex(0,0,thread_entry, thread_arg,0,0);
13 | if ((int) (*thread_id_ptr)!=-1) return 0;
14 | return -1;
15 | #else
16 | return pthread_create(thread_id_ptr,NULL,thread_entry, thread_arg);
17 | #endif
18 | }
19 |
20 | THREAD_HANDLE get_thread_id()
21 | {
22 | #ifdef WIN32
23 | return GetCurrentThread();
24 | #else
25 | return pthread_self();
26 | #endif
27 | }
28 |
29 | int join_thread(THREAD_HANDLE tid)
30 | {
31 | #ifdef WIN32
32 | return WaitForSingleObject(tid,INFINITE);
33 |
34 | #else
35 | return pthread_join(tid,NULL);
36 | #endif
37 |
38 | }
39 |
40 |
41 |
42 | /*Operating system interface for creating mutex variable*/
43 | void create_mutex(mutex_t *mtx){
44 | #ifdef WIN32
45 | InitializeCriticalSection(mtx);
46 | #else
47 | pthread_mutex_init(mtx,0);
48 | #endif
49 | }
50 |
51 | /*Operating system interface for destroying mutex variable*/
52 | void destroy_mutex(mutex_t *mtx){
53 | #ifdef WIN32
54 | DeleteCriticalSection(mtx);
55 | #else
56 | pthread_mutex_destroy(mtx);
57 | #endif
58 | }
59 |
60 | /*Operating system interface for locking mutex variable*/
61 | void lock_mutex(mutex_t *mtx){
62 | #ifdef WIN32
63 | EnterCriticalSection(mtx);
64 | #else
65 | pthread_mutex_lock(mtx);
66 | #endif
67 | }
68 |
69 | /*Operating system interface for unlocking(signal) mutex variable*/
70 | void unlock_mutex(mutex_t *mtx){
71 | #ifdef WIN32
72 | LeaveCriticalSection(mtx);
73 | #else
74 | pthread_mutex_unlock(mtx);
75 | #endif
76 | }
77 |
78 | void init_event(my_event *evnt,int init_state){
79 | #ifdef WIN32
80 | evnt->_handle = CreateEvent(0, 0,init_state, 0); /* create event */
81 | #else
82 | pthread_cond_init(&(evnt->_handle._cond), 0); /* init condition thread */
83 | evnt->_handle._signaled = init_state; /* set initial state */
84 | pthread_mutex_init(&(evnt->_handle._mtx),0);
85 | #endif
86 | }
87 | void destroy_event(my_event *evnt){
88 | #ifdef WIN32
89 | CloseHandle(evnt->_handle); /* close event handle */
90 | #else
91 | pthread_cond_destroy(&(evnt->_handle._cond)); /* destroy condition thread */
92 | pthread_mutex_destroy(&(evnt->_handle._mtx));
93 | #endif
94 | }
95 | void signal_event(my_event *evnt){
96 | #ifdef WIN32
97 | /* set event to the signal state */
98 | SetEvent(evnt->_handle);
99 | #else
100 | /* lock mutex */
101 | pthread_mutex_lock(&(evnt->_handle._mtx));
102 | pthread_cond_signal(&evnt->_handle._cond); /* Unblock just one waiter */
103 | evnt->_handle._signaled = 1;
104 | pthread_mutex_unlock(&(evnt->_handle._mtx));
105 | #endif
106 | }
107 |
108 |
109 |
110 | int event_wait(my_event *evnt,int timeout){
111 | #ifdef WIN32
112 | /* wait signal */
113 | return WaitForSingleObject(evnt->_handle, timeout);
114 | #else
115 | const size_t os_minus_one = ~0;
116 | int ret = 0; /* If we don't do anything it's because it's free already */
117 | /* If the event is not in the signaled state, we will have to wait. */
118 | pthread_mutex_lock(&(evnt->_handle._mtx));
119 |
120 | if (!evnt->_handle._signaled) /* if signal has not been set to 1, wait by pthread_cond_... */
121 | {
122 | if (!timeout) /* no time for waiting */{
123 | pthread_mutex_unlock(&(evnt->_handle._mtx));
124 | return WAIT_TIMEOUT;
125 | }else{
126 | struct timespec timeout_;
127 | if (INFINITE != timeout){
128 | /* set timeout */
129 | struct timeval now_;
130 | gettimeofday(&now_, 0);
131 | timeout_.tv_sec = now_.tv_sec + timeout / 1000;
132 | timeout_.tv_nsec = (((timeout % 1000) * 1000 + now_.tv_usec) % 1000000) * 1000;
133 | }
134 |
135 | /* wait until condition thread returns control */
136 |
137 | if (INFINITE == timeout)
138 | ret=pthread_cond_wait(&(evnt->_handle._cond),& (evnt->_handle._mtx)) ;
139 | else
140 | ret=pthread_cond_timedwait(&(evnt->_handle._cond),&(evnt->_handle._mtx), &timeout_);
141 |
142 |
143 |
144 | }
145 | }
146 | else /*another thread has set it to 1, no need to wait on pthread_cond_....!!!*/
147 | evnt->_handle._signaled = 0; /*2012-12-17 add to switch the variable from 1 to 0.*/
148 |
149 |
150 | /* adjust signaled member */
151 | switch (ret)
152 | {
153 | case 0: /* success */
154 | pthread_mutex_unlock(&(evnt->_handle._mtx));
155 | return WAIT_OBJECT_0;
156 | case ETIMEDOUT:
157 | default:
158 | pthread_mutex_unlock(&(evnt->_handle._mtx));
159 | return WAIT_TIMEOUT;
160 | }
161 | #endif
162 | }
163 |
164 | #ifndef WIN32
165 | void Sleep(unsigned int millis){
166 | struct timespec req , rem ;
167 | req.tv_sec = millis / 1000 ;
168 | req.tv_nsec = (millis % 1000) *1000000 ;
169 | while ( nanosleep(&req, &rem) == -1 )
170 | {
171 | if ( errno != EINTR ) break ;
172 | req.tv_sec = rem.tv_sec ;
173 | req.tv_nsec = rem.tv_nsec ;
174 | }
175 | }
176 | #endif
177 |
178 |
179 |
--------------------------------------------------------------------------------
/ksmdb/samples/multithread/tools.h:
--------------------------------------------------------------------------------
1 | #ifndef _TOOLS_H_
2 | #define _TOOLS_H_
3 |
4 | /*Header files */
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #ifdef WIN32
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #else
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #endif
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | /*
30 | * thread functions.
31 | */
32 |
33 | #ifdef WIN32
34 | typedef HANDLE THREAD_HANDLE ;
35 |
36 | typedef unsigned int (_stdcall *ThreadProc)(void *);
37 |
38 | #else
39 | typedef pthread_t THREAD_HANDLE ;
40 | typedef void* (*ThreadProc)(void *);
41 | #endif
42 |
43 | /*
44 | * return 0: success.
45 | * -1: failure.
46 | */
47 | int create_thread(THREAD_HANDLE *thread_id_ptr, ThreadProc thread_entry, void *thread_arg);
48 |
49 | THREAD_HANDLE get_thread_id();
50 |
51 | int join_thread(THREAD_HANDLE tid);
52 |
53 |
54 |
55 | #ifdef WIN32
56 | typedef CRITICAL_SECTION mutex_t;
57 | #define PTHREAD_CANCELLED 0
58 | #define THREAD_RETURN_VALUE PTHREAD_CANCELLED
59 | #define THREAD_RETURN_TYPE unsigned __stdcall
60 |
61 | #else
62 | #define WAIT_TIMEOUT 0x00000102L
63 | #define WAIT_OBJECT_0 0
64 | #define INFINITE -1
65 | typedef pthread_mutex_t mutex_t;
66 | typedef unsigned int DWORD;
67 | #ifndef PTHREAD_CANCELED
68 | #define PTHREAD_CANCELED 0
69 | #endif
70 | #define THREAD_RETURN_TYPE void *
71 | #define THREAD_RETURN_VALUE PTHREAD_CANCELED
72 |
73 | #endif
74 |
75 | #ifndef WIN32
76 | typedef struct {
77 | pthread_mutex_t _mtx;
78 | pthread_cond_t _cond;
79 | int _signaled;
80 | } HANDLE;
81 | #endif
82 |
83 | typedef struct{
84 | HANDLE _handle;
85 | }my_event;
86 |
87 | /*Initialize the event object */
88 | void init_event(my_event *evnt,int init_state);
89 | /*Wait on the event object for specified time */
90 | int event_wait(my_event *evnt,int timeout);
91 |
92 |
93 |
94 | /*Signal the event */
95 | void signal_event(my_event *evnt);
96 | /*destroy the event */
97 | void destroy_event(my_event *evnt);
98 |
99 |
100 | void create_mutex(mutex_t *mtx);
101 | void destroy_mutex(mutex_t *mtx);
102 | void lock_mutex(mutex_t *mtx);
103 | void unlock_mutex(mutex_t *mtx);
104 | #ifndef WIN32
105 | void Sleep(unsigned int millis);
106 | #endif
107 |
108 |
109 |
110 | #ifdef __cplusplus
111 | }
112 | #endif
113 |
114 |
115 | #endif
116 |
--------------------------------------------------------------------------------
/ksmdb/samples/samples.ncb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/samples.ncb
--------------------------------------------------------------------------------
/ksmdb/samples/samples.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28307.1062
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchmark", "benchmark\benchmark.vcxproj", "{02F72C85-3C82-4936-897E-752698B6E43D}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simpleksmdb", "simpleksmdb\simpleksmdb.vcxproj", "{93655541-823A-4826-BC5F-A0F66D736830}"
9 | EndProject
10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "backup", "backup\backup.vcxproj", "{3FB3A0F5-2309-47D7-ADAA-4458C2AF0C58}"
11 | EndProject
12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "errhandler", "errhandler\errhandler.vcxproj", "{6421F65F-8E9B-46DA-9EF7-BDF08566B26B}"
13 | EndProject
14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multithread", "multithread\multithread.vcxproj", "{5F19BA37-E920-4CA5-81D3-8DDF251EF72C}"
15 | EndProject
16 | Global
17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
18 | Debug|Win32 = Debug|Win32
19 | Release|Win32 = Release|Win32
20 | EndGlobalSection
21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
22 | {02F72C85-3C82-4936-897E-752698B6E43D}.Debug|Win32.ActiveCfg = Debug|Win32
23 | {02F72C85-3C82-4936-897E-752698B6E43D}.Debug|Win32.Build.0 = Debug|Win32
24 | {02F72C85-3C82-4936-897E-752698B6E43D}.Release|Win32.ActiveCfg = Release|Win32
25 | {02F72C85-3C82-4936-897E-752698B6E43D}.Release|Win32.Build.0 = Release|Win32
26 | {93655541-823A-4826-BC5F-A0F66D736830}.Debug|Win32.ActiveCfg = Debug|Win32
27 | {93655541-823A-4826-BC5F-A0F66D736830}.Debug|Win32.Build.0 = Debug|Win32
28 | {93655541-823A-4826-BC5F-A0F66D736830}.Release|Win32.ActiveCfg = Release|Win32
29 | {93655541-823A-4826-BC5F-A0F66D736830}.Release|Win32.Build.0 = Release|Win32
30 | {3FB3A0F5-2309-47D7-ADAA-4458C2AF0C58}.Debug|Win32.ActiveCfg = Debug|Win32
31 | {3FB3A0F5-2309-47D7-ADAA-4458C2AF0C58}.Debug|Win32.Build.0 = Debug|Win32
32 | {3FB3A0F5-2309-47D7-ADAA-4458C2AF0C58}.Release|Win32.ActiveCfg = Release|Win32
33 | {3FB3A0F5-2309-47D7-ADAA-4458C2AF0C58}.Release|Win32.Build.0 = Release|Win32
34 | {6421F65F-8E9B-46DA-9EF7-BDF08566B26B}.Debug|Win32.ActiveCfg = Debug|Win32
35 | {6421F65F-8E9B-46DA-9EF7-BDF08566B26B}.Debug|Win32.Build.0 = Debug|Win32
36 | {6421F65F-8E9B-46DA-9EF7-BDF08566B26B}.Release|Win32.ActiveCfg = Release|Win32
37 | {6421F65F-8E9B-46DA-9EF7-BDF08566B26B}.Release|Win32.Build.0 = Release|Win32
38 | {5F19BA37-E920-4CA5-81D3-8DDF251EF72C}.Debug|Win32.ActiveCfg = Debug|Win32
39 | {5F19BA37-E920-4CA5-81D3-8DDF251EF72C}.Debug|Win32.Build.0 = Debug|Win32
40 | {5F19BA37-E920-4CA5-81D3-8DDF251EF72C}.Release|Win32.ActiveCfg = Release|Win32
41 | {5F19BA37-E920-4CA5-81D3-8DDF251EF72C}.Release|Win32.Build.0 = Release|Win32
42 | EndGlobalSection
43 | GlobalSection(SolutionProperties) = preSolution
44 | HideSolutionNode = FALSE
45 | EndGlobalSection
46 | GlobalSection(ExtensibilityGlobals) = postSolution
47 | SolutionGuid = {8A8FD9FC-6E4F-448A-8BE5-714DB04DC47F}
48 | EndGlobalSection
49 | EndGlobal
50 |
--------------------------------------------------------------------------------
/ksmdb/samples/samples.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/samples.suo
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/build.sh:
--------------------------------------------------------------------------------
1 | ../../bin/linux/kstbcmp db_def.ks student
2 |
3 | make
4 |
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/db_def.ks:
--------------------------------------------------------------------------------
1 | declare database student;
2 | class grade
3 | {
4 | int4 id;
5 | string<50> name;
6 | string<10> classroom;
7 | double<0> math;
8 | double<0> Chinese;
9 | double<0> english;
10 | unique tree pkey;
11 | tree nameindex;
12 | tree classroom;
13 | tree nameclassroom;
14 | };
15 |
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/grade:
--------------------------------------------------------------------------------
1 | origin_index_name=pkey(id)
2 | key=0:0
3 | key=1:1
4 | key=2:2
5 | key=3:3
6 | key=4:4
7 | key=5:5
8 | key=6:6
9 | key=7:7
10 | key=8:8
11 | key=9:9
12 | key=10:10
13 | key=11:11
14 | key=12:12
15 | key=13:13
16 | key=14:14
17 | key=15:15
18 | key=16:16
19 | key=17:17
20 | key=18:18
21 | key=19:19
22 | key=20:20
23 | key=21:21
24 | key=22:22
25 | key=23:23
26 | key=24:24
27 | key=25:25
28 | key=26:26
29 | key=27:27
30 | key=28:28
31 | key=29:29
32 | key=30:30
33 | key=31:31
34 | key=32:32
35 | key=33:33
36 | key=34:34
37 | key=35:35
38 | key=36:36
39 | key=37:37
40 | key=38:38
41 | key=39:39
42 | key=40:40
43 | key=41:41
44 | key=42:42
45 | key=43:43
46 | key=44:44
47 | key=45:45
48 | key=46:46
49 | key=47:47
50 | key=48:48
51 | key=49:49
52 | key=50:50
53 | key=51:51
54 | key=52:52
55 | key=53:53
56 | key=54:54
57 | key=55:55
58 | key=56:56
59 | key=57:57
60 | key=58:58
61 | key=59:59
62 | key=60:60
63 | key=61:61
64 | key=62:62
65 | key=63:63
66 | key=64:64
67 | key=65:65
68 | key=66:66
69 | key=67:67
70 | key=68:68
71 | key=69:69
72 | key=70:70
73 | key=71:71
74 | key=72:72
75 | key=73:73
76 | key=74:74
77 | key=75:75
78 | key=76:76
79 | key=77:77
80 | key=78:78
81 | key=79:79
82 | key=80:80
83 | key=81:81
84 | key=82:82
85 | key=83:83
86 | key=84:84
87 | key=85:85
88 | key=86:86
89 | key=87:87
90 | key=88:88
91 | key=89:89
92 | key=90:90
93 | key=91:91
94 | key=92:92
95 | key=93:93
96 | key=94:94
97 | key=95:95
98 | key=96:96
99 | key=97:97
100 | key=98:98
101 | key=99:99
102 | origin_index_name=nameindex(name)
103 | key=0:0:13:26:39:52:65:78:91
104 | key=1:1:14:27:40:53:66:79:92
105 | key=10:10:23:36:49:62:75:88
106 | key=11:11:24:37:50:63:76:89
107 | key=12:12:25:38:51:64:77:90
108 | key=2:2:15:28:41:54:67:80:93
109 | key=3:3:16:29:42:55:68:81:94
110 | key=4:4:17:30:43:56:69:82:95
111 | key=5:5:18:31:44:57:70:83:96
112 | key=6:6:19:32:45:58:71:84:97
113 | key=7:7:20:33:46:59:72:85:98
114 | key=8:8:21:34:47:60:73:86:99
115 | key=9:9:22:35:48:61:74:87
116 | origin_index_name=classroom(classroom)
117 | key=0:0:16:32:48:64:80:96
118 | key=1:1:17:33:49:65:81:97
119 | key=10:10:26:42:58:74:90
120 | key=11:11:27:43:59:75:91
121 | key=12:12:28:44:60:76:92
122 | key=13:13:29:45:61:77:93
123 | key=14:14:30:46:62:78:94
124 | key=15:15:31:47:63:79:95
125 | key=2:2:18:34:50:66:82:98
126 | key=3:3:19:35:51:67:83:99
127 | key=4:4:20:36:52:68:84
128 | key=5:5:21:37:53:69:85
129 | key=6:6:22:38:54:70:86
130 | key=7:7:23:39:55:71:87
131 | key=8:8:24:40:56:72:88
132 | key=9:9:25:41:57:73:89
133 | origin_index_name=nameclassroom(name,classroom)
134 | key=0,0:0
135 | key=0,1:65
136 | key=0,10:26
137 | key=0,11:91
138 | key=0,13:13
139 | key=0,14:78
140 | key=0,4:52
141 | key=0,7:39
142 | key=1,1:1
143 | key=1,11:27
144 | key=1,12:92
145 | key=1,14:14
146 | key=1,15:79
147 | key=1,2:66
148 | key=1,5:53
149 | key=1,8:40
150 | key=10,1:49
151 | key=10,10:10
152 | key=10,11:75
153 | key=10,14:62
154 | key=10,4:36
155 | key=10,7:23
156 | key=10,8:88
157 | key=11,11:11
158 | key=11,12:76
159 | key=11,15:63
160 | key=11,2:50
161 | key=11,5:37
162 | key=11,8:24
163 | key=11,9:89
164 | key=12,0:64
165 | key=12,10:90
166 | key=12,12:12
167 | key=12,13:77
168 | key=12,3:51
169 | key=12,6:38
170 | key=12,9:25
171 | key=2,0:80
172 | key=2,12:28
173 | key=2,13:93
174 | key=2,15:15
175 | key=2,2:2
176 | key=2,3:67
177 | key=2,6:54
178 | key=2,9:41
179 | key=3,0:16
180 | key=3,1:81
181 | key=3,10:42
182 | key=3,13:29
183 | key=3,14:94
184 | key=3,3:3
185 | key=3,4:68
186 | key=3,7:55
187 | key=4,1:17
188 | key=4,11:43
189 | key=4,14:30
190 | key=4,15:95
191 | key=4,2:82
192 | key=4,4:4
193 | key=4,5:69
194 | key=4,8:56
195 | key=5,0:96
196 | key=5,12:44
197 | key=5,15:31
198 | key=5,2:18
199 | key=5,3:83
200 | key=5,5:5
201 | key=5,6:70
202 | key=5,9:57
203 | key=6,0:32
204 | key=6,1:97
205 | key=6,10:58
206 | key=6,13:45
207 | key=6,3:19
208 | key=6,4:84
209 | key=6,6:6
210 | key=6,7:71
211 | key=7,1:33
212 | key=7,11:59
213 | key=7,14:46
214 | key=7,2:98
215 | key=7,4:20
216 | key=7,5:85
217 | key=7,7:7
218 | key=7,8:72
219 | key=8,12:60
220 | key=8,15:47
221 | key=8,2:34
222 | key=8,3:99
223 | key=8,5:21
224 | key=8,6:86
225 | key=8,8:8
226 | key=8,9:73
227 | key=9,0:48
228 | key=9,10:74
229 | key=9,13:61
230 | key=9,3:35
231 | key=9,6:22
232 | key=9,7:87
233 | key=9,9:9
234 | curent_index_name=pkey(id)
235 | key=0:0
236 | key=1:1
237 | key=2:2
238 | key=3:3
239 | key=4:4
240 | key=5:5
241 | key=6:6
242 | key=7:7
243 | key=8:8
244 | key=9:9
245 | key=10:10
246 | key=11:11
247 | key=12:12
248 | key=13:13
249 | key=14:14
250 | key=15:15
251 | key=16:16
252 | key=17:17
253 | key=18:18
254 | key=19:19
255 | key=20:20
256 | key=21:21
257 | key=22:22
258 | key=23:23
259 | key=24:24
260 | key=25:25
261 | key=26:26
262 | key=27:27
263 | key=28:28
264 | key=29:29
265 | key=30:30
266 | key=31:31
267 | key=32:32
268 | key=33:33
269 | key=34:34
270 | key=35:35
271 | key=36:36
272 | key=37:37
273 | key=38:38
274 | key=39:39
275 | key=40:40
276 | key=41:41
277 | key=42:42
278 | key=43:43
279 | key=44:44
280 | key=45:45
281 | key=46:46
282 | key=47:47
283 | key=48:48
284 | key=49:49
285 | key=50:50
286 | key=51:51
287 | key=52:52
288 | key=53:53
289 | key=54:54
290 | key=55:55
291 | key=56:56
292 | key=57:57
293 | key=58:58
294 | key=59:59
295 | key=60:60
296 | key=61:61
297 | key=62:62
298 | key=63:63
299 | key=64:64
300 | key=65:65
301 | key=66:66
302 | key=67:67
303 | key=68:68
304 | key=69:69
305 | key=70:70
306 | key=71:71
307 | key=72:72
308 | key=73:73
309 | key=74:74
310 | key=75:75
311 | key=76:76
312 | key=77:77
313 | key=78:78
314 | key=79:79
315 | key=80:80
316 | key=81:81
317 | key=82:82
318 | key=83:83
319 | key=84:84
320 | key=85:85
321 | key=86:86
322 | key=87:87
323 | key=88:88
324 | key=89:89
325 | key=90:90
326 | key=91:91
327 | key=92:92
328 | key=93:93
329 | key=94:94
330 | key=95:95
331 | key=96:96
332 | key=97:97
333 | key=98:98
334 | key=99:99
335 | curent_index_name=nameindex(name)
336 | key=0:0:13:26:39:52:65:78:91
337 | key=1:1:14:27:40:53:66:79:92
338 | key=10:10:23:36:49:62:75:88
339 | key=11:11:24:37:50:63:76:89
340 | key=12:12:25:38:51:64:77:90
341 | key=2:2:15:28:41:54:67:80:93
342 | key=3:3:16:29:42:55:68:81:94
343 | key=4:4:17:30:43:56:69:82:95
344 | key=5:5:18:31:44:57:70:83:96
345 | key=6:6:19:32:45:58:71:84:97
346 | key=7:7:20:33:46:59:72:85:98
347 | key=8:8:21:34:47:60:73:86
348 | key=9:9:22:35:48:61:74:87
349 | curent_index_name=classroom(classroom)
350 | key=0:0:16:32:48:64:80:96
351 | key=1:1:17:33:49:65:81:97
352 | key=10:10:26:42:58:74:90
353 | key=11:11:27:43:59:75:91
354 | key=12:12:28:44:60:76:92
355 | key=13:13:29:45:61:77:93
356 | key=14:14:30:46:62:78:94
357 | key=15:15:31:47:63:79:95
358 | key=2:2:18:34:50:66:82:98
359 | key=3:3:19:35:51:67:83:99
360 | key=4:4:20:36:52:68:84
361 | key=5:5:21:37:53:69:85
362 | key=6:6:22:38:54:70:86
363 | key=7:7:23:39:55:71:87
364 | key=8:8:24:40:56:72:88
365 | key=9:9:25:41:57:73:89
366 | curent_index_name=nameclassroom(name,classroom)
367 | key=0,0:0
368 | key=0,1:65
369 | key=0,10:26
370 | key=0,11:91
371 | key=0,13:13
372 | key=0,14:78
373 | key=0,4:52
374 | key=0,7:39
375 | key=1,1:1
376 | key=1,11:27
377 | key=1,12:92
378 | key=1,14:14
379 | key=1,15:79
380 | key=1,2:66
381 | key=1,5:53
382 | key=1,8:40
383 | key=10,1:49
384 | key=10,10:10
385 | key=10,11:75
386 | key=10,14:62
387 | key=10,4:36
388 | key=10,7:23
389 | key=10,8:88
390 | key=11,11:11
391 | key=11,12:76
392 | key=11,15:63
393 | key=11,2:50
394 | key=11,5:37
395 | key=11,8:24
396 | key=11,9:89
397 | key=12,0:64
398 | key=12,10:90
399 | key=12,12:12
400 | key=12,13:77
401 | key=12,3:51
402 | key=12,6:38
403 | key=12,9:25
404 | key=2,0:80
405 | key=2,12:28
406 | key=2,13:93
407 | key=2,15:15
408 | key=2,2:2
409 | key=2,3:67
410 | key=2,6:54
411 | key=2,9:41
412 | key=3,0:16
413 | key=3,1:81
414 | key=3,10:42
415 | key=3,13:29
416 | key=3,14:94
417 | key=3,3:3
418 | key=3,4:68
419 | key=3,7:55
420 | key=4,1:17
421 | key=4,11:43
422 | key=4,14:30
423 | key=4,15:95
424 | key=4,2:82
425 | key=4,4:4
426 | key=4,5:69
427 | key=4,8:56
428 | key=5,0:96
429 | key=5,12:44
430 | key=5,15:31
431 | key=5,2:18
432 | key=5,3:83
433 | key=5,5:5
434 | key=5,6:70
435 | key=5,9:57
436 | key=6,0:32
437 | key=6,1:97
438 | key=6,10:58
439 | key=6,13:45
440 | key=6,3:19
441 | key=6,4:84
442 | key=6,6:6
443 | key=6,7:71
444 | key=7,1:33
445 | key=7,11:59
446 | key=7,14:46
447 | key=7,2:98
448 | key=7,4:20
449 | key=7,5:85
450 | key=7,7:7
451 | key=7,8:72
452 | key=8,12:60
453 | key=8,15:47
454 | key=8,2:34
455 | key=8,5:21
456 | key=8,6:86
457 | key=8,8:8
458 | key=8,9:73
459 | key=9,0:48
460 | key=9,10:74
461 | key=9,13:61
462 | key=9,3:35
463 | key=9,6:22
464 | key=9,7:87
465 | key=9,9:9
466 | tablename=grade(id,name,classroom,math,Chinese,english)
467 | ID=0,DELETE=FALSE,data=0,0,0,0,0,0
468 | ID=1,DELETE=FALSE,data=1,1,1,1,1,1
469 | ID=2,DELETE=FALSE,data=2,2,2,2,2,2
470 | ID=3,DELETE=FALSE,data=3,3,3,3,3,3
471 | ID=4,DELETE=FALSE,data=4,4,4,4,4,4
472 | ID=5,DELETE=FALSE,data=5,5,5,5,5,5
473 | ID=6,DELETE=FALSE,data=6,6,6,6,6,6
474 | ID=7,DELETE=FALSE,data=7,7,7,7,7,7
475 | ID=8,DELETE=FALSE,data=8,8,8,8,8,8
476 | ID=9,DELETE=FALSE,data=9,9,9,9,9,9
477 | ID=10,DELETE=FALSE,data=10,10,10,10,10,10
478 | ID=11,DELETE=FALSE,data=11,11,11,11,11,11
479 | ID=12,DELETE=FALSE,data=12,12,12,12,12,12
480 | ID=13,DELETE=FALSE,data=13,0,13,13,13,13
481 | ID=14,DELETE=FALSE,data=14,1,14,14,14,14
482 | ID=15,DELETE=FALSE,data=15,2,15,15,15,15
483 | ID=16,DELETE=FALSE,data=16,3,0,16,16,16
484 | ID=17,DELETE=FALSE,data=17,4,1,17,17,17
485 | ID=18,DELETE=FALSE,data=18,5,2,18,18,18
486 | ID=19,DELETE=FALSE,data=19,6,3,19,19,19
487 | ID=20,DELETE=FALSE,data=20,7,4,20,20,20
488 | ID=21,DELETE=FALSE,data=21,8,5,21,21,21
489 | ID=22,DELETE=FALSE,data=22,9,6,22,22,22
490 | ID=23,DELETE=FALSE,data=23,10,7,23,23,23
491 | ID=24,DELETE=FALSE,data=24,11,8,24,24,24
492 | ID=25,DELETE=FALSE,data=25,12,9,25,25,25
493 | ID=26,DELETE=FALSE,data=26,0,10,26,26,26
494 | ID=27,DELETE=FALSE,data=27,1,11,27,27,27
495 | ID=28,DELETE=FALSE,data=28,2,12,28,28,28
496 | ID=29,DELETE=FALSE,data=29,3,13,29,29,29
497 | ID=30,DELETE=FALSE,data=30,4,14,30,30,30
498 | ID=31,DELETE=FALSE,data=31,5,15,31,31,31
499 | ID=32,DELETE=FALSE,data=32,6,0,32,32,32
500 | ID=33,DELETE=FALSE,data=33,7,1,33,33,33
501 | ID=34,DELETE=FALSE,data=34,8,2,34,34,34
502 | ID=35,DELETE=FALSE,data=35,9,3,35,35,35
503 | ID=36,DELETE=FALSE,data=36,10,4,36,36,36
504 | ID=37,DELETE=FALSE,data=37,11,5,37,37,37
505 | ID=38,DELETE=FALSE,data=38,12,6,38,38,38
506 | ID=39,DELETE=FALSE,data=39,0,7,39,39,39
507 | ID=40,DELETE=FALSE,data=40,1,8,40,40,40
508 | ID=41,DELETE=FALSE,data=41,2,9,41,41,41
509 | ID=42,DELETE=FALSE,data=42,3,10,42,42,42
510 | ID=43,DELETE=FALSE,data=43,4,11,43,43,43
511 | ID=44,DELETE=FALSE,data=44,5,12,44,44,44
512 | ID=45,DELETE=FALSE,data=45,6,13,45,45,45
513 | ID=46,DELETE=FALSE,data=46,7,14,46,46,46
514 | ID=47,DELETE=FALSE,data=47,8,15,47,47,47
515 | ID=48,DELETE=FALSE,data=48,9,0,48,48,48
516 | ID=49,DELETE=FALSE,data=49,10,1,49,49,49
517 | ID=50,DELETE=FALSE,data=50,11,2,50,50,50
518 | ID=51,DELETE=FALSE,data=51,12,3,51,51,51
519 | ID=52,DELETE=FALSE,data=52,0,4,52,52,52
520 | ID=53,DELETE=FALSE,data=53,1,5,53,53,53
521 | ID=54,DELETE=FALSE,data=54,2,6,54,54,54
522 | ID=55,DELETE=FALSE,data=55,3,7,55,55,55
523 | ID=56,DELETE=FALSE,data=56,4,8,56,56,56
524 | ID=57,DELETE=FALSE,data=57,5,9,57,57,57
525 | ID=58,DELETE=FALSE,data=58,6,10,58,58,58
526 | ID=59,DELETE=FALSE,data=59,7,11,59,59,59
527 | ID=60,DELETE=FALSE,data=60,8,12,60,60,60
528 | ID=61,DELETE=FALSE,data=61,9,13,61,61,61
529 | ID=62,DELETE=FALSE,data=62,10,14,62,62,62
530 | ID=63,DELETE=FALSE,data=63,11,15,63,63,63
531 | ID=64,DELETE=FALSE,data=64,12,0,64,64,64
532 | ID=65,DELETE=FALSE,data=65,0,1,65,65,65
533 | ID=66,DELETE=FALSE,data=66,1,2,66,66,66
534 | ID=67,DELETE=FALSE,data=67,2,3,67,67,67
535 | ID=68,DELETE=FALSE,data=68,3,4,68,68,68
536 | ID=69,DELETE=FALSE,data=69,4,5,69,69,69
537 | ID=70,DELETE=FALSE,data=70,5,6,70,70,70
538 | ID=71,DELETE=FALSE,data=71,6,7,71,71,71
539 | ID=72,DELETE=FALSE,data=72,7,8,72,72,72
540 | ID=73,DELETE=FALSE,data=73,8,9,73,73,73
541 | ID=74,DELETE=FALSE,data=74,9,10,74,74,74
542 | ID=75,DELETE=FALSE,data=75,10,11,75,75,75
543 | ID=76,DELETE=FALSE,data=76,11,12,76,76,76
544 | ID=77,DELETE=FALSE,data=77,12,13,77,77,77
545 | ID=78,DELETE=FALSE,data=78,0,14,78,78,78
546 | ID=79,DELETE=FALSE,data=79,1,15,79,79,79
547 | ID=80,DELETE=FALSE,data=80,2,0,80,80,80
548 | ID=81,DELETE=FALSE,data=81,3,1,81,81,81
549 | ID=82,DELETE=FALSE,data=82,4,2,82,82,82
550 | ID=83,DELETE=FALSE,data=83,5,3,83,83,83
551 | ID=84,DELETE=FALSE,data=84,6,4,84,84,84
552 | ID=85,DELETE=FALSE,data=85,7,5,85,85,85
553 | ID=86,DELETE=FALSE,data=86,8,6,86,86,86
554 | ID=87,DELETE=FALSE,data=87,9,7,87,87,87
555 | ID=88,DELETE=FALSE,data=88,10,8,88,88,88
556 | ID=89,DELETE=FALSE,data=89,11,9,89,89,89
557 | ID=90,DELETE=FALSE,data=90,12,10,90,90,90
558 | ID=91,DELETE=FALSE,data=91,0,11,91,91,91
559 | ID=92,DELETE=FALSE,data=92,1,12,92,92,92
560 | ID=93,DELETE=FALSE,data=93,2,13,93,93,93
561 | ID=94,DELETE=FALSE,data=94,3,14,94,94,94
562 | ID=95,DELETE=FALSE,data=95,4,15,95,95,95
563 | ID=96,DELETE=FALSE,data=96,5,0,96,96,96
564 | ID=97,DELETE=FALSE,data=97,6,1,97,97,97
565 | ID=98,DELETE=FALSE,data=98,7,2,98,98,98
566 | ID=99,DELETE=TRUE,data=99,8,3,99,99,99
567 |
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/grade.tb:
--------------------------------------------------------------------------------
1 | 20210423-09:54:56:000
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/makefile:
--------------------------------------------------------------------------------
1 | CXX = g++
2 | CXXFLAGS = -g
3 | LINK = $(CXX)
4 |
5 | INCLD = -I../../include
6 | LIBS = -L../../lib/linux -lksmdb -lm -lrt -lstdc++ -lpthread
7 |
8 | TARGET = simpleksmdb
9 |
10 | OBJS = student.o test.o
11 |
12 | all:$(TARGET)
13 |
14 | simpleksmdb:$(OBJS)
15 | $(LINK) -static -o simpleksmdb $(OBJS) $(INCLD) $(LIBS)
16 | rm -rf *.o
17 |
18 | .cpp.o:
19 | $(CXX) $(CXXFLAGS) $(INCLD) -c $< -o $@
20 |
21 | clean:
22 | rm -f *.o
23 | rm -f simpleksmdb
24 |
25 |
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/qzh:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/simpleksmdb/qzh
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/simpleksmdb.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {93655541-823A-4826-BC5F-A0F66D736830}
15 | simpleksmdb
16 | Win32Proj
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | v141
23 | Unicode
24 | true
25 |
26 |
27 | Application
28 | v141
29 | Unicode
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | <_ProjectFileVersion>15.0.28307.799
43 |
44 |
45 | $(SolutionDir)$(Configuration)\
46 | $(Configuration)\
47 | true
48 |
49 |
50 | $(SolutionDir)$(Configuration)\
51 | $(Configuration)\
52 | false
53 |
54 |
55 |
56 | Disabled
57 | ..\..\include;%(AdditionalIncludeDirectories)
58 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
59 | true
60 | EnableFastChecks
61 | MultiThreadedDebugDLL
62 |
63 | Level3
64 | EditAndContinue
65 |
66 |
67 | ksmdb.lib;%(AdditionalDependencies)
68 | $(SolutionDir)..\bin\simpleksmdb.exe
69 | ..\..\lib\windows;%(AdditionalLibraryDirectories)
70 | true
71 | Console
72 | MachineX86
73 |
74 |
75 |
76 |
77 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
78 | MultiThreadedDLL
79 |
80 | Level3
81 | ProgramDatabase
82 | $(SolutionDir)\..\include
83 |
84 |
85 | true
86 | Console
87 | true
88 | true
89 | MachineX86
90 | ksmdb32.lib;ws2_32.lib;%(AdditionalDependencies)
91 | $(SolutionDir)/../lib/windows/;%(AdditionalLibraryDirectories)
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/student.cpp:
--------------------------------------------------------------------------------
1 | #include "student.h"
2 | DB_student::DB_student()
3 | {
4 | m_inited = false;
5 | m_database = NULL;
6 | }
7 |
8 | bool DB_student::Create(char *path,char *name,size_t size)
9 | {
10 | if(m_inited)
11 | {
12 | return true;
13 | }
14 | m_inited=true;
15 | if (KsCreateDb(&m_database,path,name,"20210423-10:09:51:000",size) == true)
16 | {
17 | KsAddTable(m_database,"grade");
18 | KsAddField(m_database,0,"id",KSTYPE_INT4,4,-1);
19 | KsAddField(m_database,0,"name",KSTYPE_STRING,51,-1);
20 | KsAddField(m_database,0,"classroom",KSTYPE_STRING,11,-1);
21 | KsAddField(m_database,0,"math",KSTYPE_DOUBLE,8,0);
22 | KsAddField(m_database,0,"Chinese",KSTYPE_DOUBLE,8,0);
23 | KsAddField(m_database,0,"english",KSTYPE_DOUBLE,8,0);
24 | KsAddIndex(m_database,0,"pkey",UNIQUE_INDEX);
25 | KsAddIndexField(m_database,0,0,0);
26 | KsAddIndex(m_database,0,"nameindex",NONUNIQUE_INDEX);
27 | KsAddIndexField(m_database,0,1,1);
28 | KsAddIndex(m_database,0,"classroom",NONUNIQUE_INDEX);
29 | KsAddIndexField(m_database,0,2,2);
30 | KsAddIndex(m_database,0,"nameclassroom",NONUNIQUE_INDEX);
31 | KsAddIndexField(m_database,0,3,1);
32 | KsAddIndexField(m_database,0,3,2);
33 | KsSaveDbInfo(m_database);
34 | }
35 | else
36 | {
37 | m_inited=false;
38 | return false;
39 | }
40 | KsLoadDb(m_database);
41 | return true;
42 | };
43 |
44 | bool DB_student::Open(char *path,char *name,int mode,int port,bool isolate,int reuse_shmmap, int shmrcset_mode)
45 | {
46 | if(m_inited)
47 | {
48 | return true;
49 | }
50 | m_inited=true;
51 | if (KsOpenDb(&m_database,path,name,"20210423-10:09:51:000",mode,port,isolate, reuse_shmmap, shmrcset_mode) == true)
52 | {
53 | KsLoadDbInfo(m_database);
54 | }
55 | else
56 | {
57 | m_inited=false;
58 | return false;
59 | }
60 | KsLoadDb(m_database);
61 | return true;
62 | };
63 |
64 | void DB_student::UnLockDb()
65 | {
66 | KsUnLockDb(m_database);
67 | }
68 |
69 | void DB_student::SetErrorHandle(KsErrorHandle handle)
70 | {
71 | KsSetErrorHandle(m_database,handle);
72 | }
73 |
74 | int DB_student::GetCols(KsRecordHandle handle)
75 | {
76 | return KsGetCols(m_database,handle);
77 | }
78 |
79 | char *DB_student::GetColName(KsRecordHandle handle,int col)
80 | {
81 | return KsGetColName(m_database,handle,col);
82 | }
83 |
84 | int DB_student::GetColType(KsRecordHandle handle,int col)
85 | {
86 | return KsGetColType(m_database,handle,col);
87 | }
88 |
89 | int DB_student::GetColSize(KsRecordHandle handle,int col)
90 | {
91 | return KsGetColSize(m_database,handle,col);
92 | }
93 |
94 | int DB_student::GetColDecimal(KsRecordHandle handle,int col)
95 | {
96 | return KsGetColDecimal(m_database,handle,col);
97 | }
98 |
99 | char *DB_student::GetColData(KsRecordHandle handle,int col)
100 | {
101 | return KsGetColData(m_database,handle,col);
102 | }
103 |
104 | void DB_student::GetMemoryInfo(size_t &size,size_t &inused)
105 | {
106 | KsMemoryInfo(m_database,&size,&inused);
107 | }
108 |
109 | void DB_student::Reset()
110 | {
111 | KsResetDb(m_database);
112 | }
113 |
114 | bool DB_student::Backup(char *filename)
115 | {
116 | return KsWriteDbFile(m_database,filename);
117 | }
118 |
119 | bool DB_student::Load(char *filename)
120 | {
121 | return KsReadDbFile(m_database,filename);
122 | }
123 |
124 | void DB_student::BeginTransaction()
125 | {
126 | KsBeginTransaction(m_database);
127 | }
128 |
129 | void DB_student::RollbackTransaction()
130 | {
131 | KsRollbackTransaction(m_database);
132 | }
133 |
134 | void DB_student::CommitTransaction()
135 | {
136 | KsCommitTransaction(m_database);
137 | }
138 |
139 | void DB_student::GetLastError(int *errcode,char *errmsg)
140 | {
141 | KsGetError(m_database,*errcode,errmsg);
142 | }
143 |
144 | void DB_student::Close()
145 | {
146 | KsDeleteDb(m_database);
147 | m_inited=false;
148 | }
149 |
150 | char* DB_student::LibVersion()
151 | {
152 | return KsGetLibVersion();
153 | }
154 |
155 | char* DB_student::DbVersion()
156 | {
157 | return KsGetDbVersion(m_database);
158 | }
159 |
160 | KsDbHandle DB_student::GetDBHandle()
161 | {
162 | return m_database;
163 | }
164 |
165 | TB_grade::TB_grade(KsDbHandle database)
166 | {
167 | m_database = database;
168 | KsCreateCondition(2,&m_condition);
169 | KsCreateRecord(&m_record);
170 | }
171 |
172 | TB_grade::TB_grade(TB_grade &V)
173 | {
174 | KsCreateCondition(2,&m_condition);
175 | KsCreateRecord(&m_record);
176 | KsDupCondition(V.m_condition,m_condition);
177 | KsDupRecord(V.m_record,m_record);
178 | }
179 |
180 | TB_grade::~TB_grade()
181 | {
182 | KsCloseCondition(m_condition);
183 | KsCloseRecord(m_database,m_record);
184 | }
185 |
186 | bool TB_grade::newrecord()
187 | {
188 | return KsNewRecord(m_database,0,m_record);
189 | }
190 |
191 | bool TB_grade::append(int id,char* name,char* classroom)
192 | {
193 | KsSetField(m_database,m_record,0,(char *)&id);
194 | KsSetField(m_database,m_record,1,(char *)name);
195 | KsSetField(m_database,m_record,2,(char *)classroom);
196 | return KsPutRecord(m_database,m_record);
197 | }
198 |
199 | bool TB_grade::erase()
200 | {
201 | KsDeleteRecord(m_database,m_record);
202 | return true;
203 | }
204 |
205 | bool TB_grade::first()
206 | {
207 | if(!KsFirstRecord(m_database,m_condition))
208 | {
209 | return false;
210 | }
211 | KsGetRecord(m_database,m_condition,m_record);
212 | return true;
213 | }
214 |
215 | bool TB_grade::prev()
216 | {
217 | if(!KsPrevRecord(m_database,m_condition))
218 | {
219 | return false;
220 | }
221 | KsGetRecord(m_database,m_condition,m_record);
222 | return true;
223 | }
224 |
225 | bool TB_grade::next()
226 | {
227 | if(!KsNextRecord(m_database,m_condition))
228 | {
229 | return false;
230 | }
231 | KsGetRecord(m_database,m_condition,m_record);
232 | return true;
233 | }
234 |
235 | bool TB_grade::end()
236 | {
237 | if(!KsLastRecord(m_database,m_condition))
238 | {
239 | return false;
240 | }
241 | KsGetRecord(m_database,m_condition,m_record);
242 | return true;
243 | }
244 |
245 | bool TB_grade::gotorow(int rowid)
246 | {
247 | if(!KsGotoRecord(m_database,0,rowid,m_condition))
248 | {
249 | return false;
250 | }
251 | KsGetRecord(m_database,m_condition,m_record);
252 | return true;
253 | }
254 |
255 | int TB_grade::recordrowid()
256 | {
257 | return KsGetRecordId(m_database,m_record);
258 | }
259 |
260 | bool TB_grade::dump(char *filename)
261 | {
262 | return KsDumpTable(m_database,0,filename);
263 | }
264 |
265 | bool TB_grade::SaveCsv(char *filename)
266 | {
267 | return KsWriteTableCsv(m_database,0,filename);
268 | }
269 |
270 | bool TB_grade::LoadCsv(char *filename)
271 | {
272 | return KsReadTableCsv(m_database,0,m_record,filename);
273 | }
274 |
275 | bool TB_grade::SaveTXT(char *filename)
276 | {
277 | return KsWriteTableTxt(m_database,0,filename);
278 | }
279 |
280 | bool TB_grade::LoadTXT(char *filename)
281 | {
282 | return KsReadTableTxt(m_database,0,m_record,filename);
283 | }
284 |
285 | bool TB_grade::SaveBinary(char *filename)
286 | {
287 | return KsWriteTableBinary(m_database,0,filename);
288 | }
289 |
290 | bool TB_grade::LoadBinary(char *filename)
291 | {
292 | return KsReadTableBinary(m_database,0,m_record,filename);
293 | }
294 |
295 | bool TB_grade::backup(char *filename)
296 | {
297 | return KsWriteDbTable(m_database,0,filename);
298 | }
299 |
300 | bool TB_grade::load(char *filename)
301 | {
302 | return KsReadDbTable(m_database,0,filename);
303 | }
304 |
305 | int TB_grade::get_id()
306 | {
307 | int fieldtype;
308 | int r;
309 |
310 | memcpy(&r,KsGetField(m_database,m_record,0,fieldtype),sizeof(int));
311 | return r;
312 | }
313 |
314 | char* TB_grade::get_name()
315 | {
316 | int fieldtype;
317 |
318 | return (char *)KsGetField(m_database,m_record,1,fieldtype);
319 | }
320 |
321 | char* TB_grade::get_classroom()
322 | {
323 | int fieldtype;
324 |
325 | return (char *)KsGetField(m_database,m_record,2,fieldtype);
326 | }
327 |
328 | bool TB_grade::set_math(double value)
329 | {
330 | return KsSetField(m_database,m_record,3,(char *)&value);
331 | }
332 |
333 | double TB_grade::get_math()
334 | {
335 | int fieldtype;
336 | double r;
337 |
338 | memcpy(&r,KsGetField(m_database,m_record,3,fieldtype),sizeof(double));
339 | return r;
340 | }
341 |
342 | bool TB_grade::set_Chinese(double value)
343 | {
344 | return KsSetField(m_database,m_record,4,(char *)&value);
345 | }
346 |
347 | double TB_grade::get_Chinese()
348 | {
349 | int fieldtype;
350 | double r;
351 |
352 | memcpy(&r,KsGetField(m_database,m_record,4,fieldtype),sizeof(double));
353 | return r;
354 | }
355 |
356 | bool TB_grade::set_english(double value)
357 | {
358 | return KsSetField(m_database,m_record,5,(char *)&value);
359 | }
360 |
361 | double TB_grade::get_english()
362 | {
363 | int fieldtype;
364 | double r;
365 |
366 | memcpy(&r,KsGetField(m_database,m_record,5,fieldtype),sizeof(double));
367 | return r;
368 | }
369 |
370 | bool TB_grade::find_by_pkey(int id,int op)
371 | {
372 | KsSetConditionIndex(m_condition,0);
373 | KsAddConditionIndexItem(m_condition,KSTYPE_INT4,4,(char *)&id);
374 | if (!KsFindRecord(m_database,0,m_condition,op))
375 | {
376 | return false;
377 | }
378 | KsGetRecord(m_database,m_condition,m_record);
379 | return true;
380 | }
381 |
382 | bool TB_grade::find_by_nameindex(char* name,int op)
383 | {
384 | KsSetConditionIndex(m_condition,1);
385 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,51,(char *)name);
386 | if (!KsFindRecord(m_database,0,m_condition,op))
387 | {
388 | return false;
389 | }
390 | KsGetRecord(m_database,m_condition,m_record);
391 | return true;
392 | }
393 |
394 | bool TB_grade::find_by_classroom(char* classroom,int op)
395 | {
396 | KsSetConditionIndex(m_condition,2);
397 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,11,(char *)classroom);
398 | if (!KsFindRecord(m_database,0,m_condition,op))
399 | {
400 | return false;
401 | }
402 | KsGetRecord(m_database,m_condition,m_record);
403 | return true;
404 | }
405 |
406 | bool TB_grade::find_by_nameclassroom(char* name,char* classroom,int op)
407 | {
408 | KsSetConditionIndex(m_condition,3);
409 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,51,(char *)name);
410 | KsAddConditionIndexItem(m_condition,KSTYPE_STRING,11,(char *)classroom);
411 | if (!KsFindRecord(m_database,0,m_condition,op))
412 | {
413 | return false;
414 | }
415 | KsGetRecord(m_database,m_condition,m_record);
416 | return true;
417 | }
418 |
419 | bool TB_grade::lists()
420 | {
421 | KsSetConditionIndex(m_condition,-1);
422 | if (!KsListRecord(m_database,0,m_condition))
423 | {
424 | return false;
425 | }
426 | KsGetRecord(m_database,m_condition,m_record);
427 | return true;
428 | }
429 |
430 | bool TB_grade::list_by_pkey()
431 | {
432 | KsSetConditionIndex(m_condition,0);
433 | if (!KsListRecord(m_database,0,m_condition))
434 | {
435 | return false;
436 | }
437 | KsGetRecord(m_database,m_condition,m_record);
438 | return true;
439 | }
440 |
441 | bool TB_grade::list_by_nameindex()
442 | {
443 | KsSetConditionIndex(m_condition,1);
444 | if (!KsListRecord(m_database,0,m_condition))
445 | {
446 | return false;
447 | }
448 | KsGetRecord(m_database,m_condition,m_record);
449 | return true;
450 | }
451 |
452 | bool TB_grade::list_by_classroom()
453 | {
454 | KsSetConditionIndex(m_condition,2);
455 | if (!KsListRecord(m_database,0,m_condition))
456 | {
457 | return false;
458 | }
459 | KsGetRecord(m_database,m_condition,m_record);
460 | return true;
461 | }
462 |
463 | bool TB_grade::list_by_nameclassroom()
464 | {
465 | KsSetConditionIndex(m_condition,3);
466 | if (!KsListRecord(m_database,0,m_condition))
467 | {
468 | return false;
469 | }
470 | KsGetRecord(m_database,m_condition,m_record);
471 | return true;
472 | }
473 |
474 |
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/student.h:
--------------------------------------------------------------------------------
1 | #ifndef __student_HH
2 | #define __student_HH
3 | #include "cache.h"
4 | #include
5 | class DB_student
6 | {
7 | private:
8 | bool m_inited;
9 | KsDbHandle m_database;
10 | public:
11 | DB_student();
12 | virtual ~DB_student(){};
13 | bool Create(char *path,char *name,size_t size);
14 | bool Open(char *path,char *name,int mode,int port,bool isolate, int reuse_shmmap, int shmrcset_mode=0);
15 | void UnLockDb();
16 | void SetErrorHandle(KsErrorHandle handle);
17 | int GetCols(KsRecordHandle handle);
18 | char *GetColName(KsRecordHandle handle,int col);
19 | int GetColType(KsRecordHandle handle,int col);
20 | int GetColSize(KsRecordHandle handle,int col);
21 | int GetColDecimal(KsRecordHandle handle,int col);
22 | char *GetColData(KsRecordHandle handle,int col);
23 | void GetMemoryInfo(size_t &size,size_t &inused);
24 | void Reset();
25 | bool Backup(char *filename);
26 | bool Load(char *filename);
27 | void BeginTransaction();
28 | void RollbackTransaction();
29 | void CommitTransaction();
30 | void GetLastError(int *errcode,char *errmsg);
31 | void Close();
32 | char *LibVersion();
33 | char *DbVersion();
34 | KsDbHandle GetDBHandle();
35 | };
36 |
37 | class TB_grade
38 | {
39 | private:
40 | KsDbHandle m_database;
41 | public:
42 | KsRecordHandle m_record;
43 | KsConditionHandle m_condition;
44 | public:
45 | TB_grade(KsDbHandle database);
46 | TB_grade(TB_grade &V);
47 | virtual ~TB_grade();
48 | bool newrecord();
49 | bool append(int id,char* name,char* classroom);
50 | bool erase();
51 | bool first();
52 | bool prev();
53 | bool next();
54 | bool end();
55 | bool gotorow(int rowid);
56 | int recordrowid();
57 | bool dump(char *filename="grade");
58 | bool SaveCsv(char *filename="grade.csv");
59 | bool LoadCsv(char *filename="grade.csv");
60 | bool SaveTXT(char *filename="grade.txt");
61 | bool LoadTXT(char *filename="grade.txt");
62 | bool SaveBinary(char *filename="grade.txt");
63 | bool LoadBinary(char *filename="grade.txt");
64 | bool backup(char *filename="grade");
65 | bool load(char *filename="grade");
66 | int get_id();
67 | char* get_name();
68 | char* get_classroom();
69 | bool set_math(double value);
70 | double get_math();
71 | bool set_Chinese(double value);
72 | double get_Chinese();
73 | bool set_english(double value);
74 | double get_english();
75 | bool find_by_pkey(int id,int op=EQ);
76 | bool find_by_nameindex(char* name,int op=EQ);
77 | bool find_by_classroom(char* classroom,int op=EQ);
78 | bool find_by_nameclassroom(char* name,char* classroom,int op=EQ);
79 | bool lists();
80 | bool list_by_pkey();
81 | bool list_by_nameindex();
82 | bool list_by_classroom();
83 | bool list_by_nameclassroom();
84 | };
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/student.script:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/samples/simpleksmdb/student.script
--------------------------------------------------------------------------------
/ksmdb/samples/simpleksmdb/test.cpp:
--------------------------------------------------------------------------------
1 | #include "student.h"
2 | #include
3 | #if defined(WIN32)
4 | #include
5 | #endif
6 | bool myerrhandle(int errcode,char *errmsg)
7 | {
8 | printf("my errhandle:errcode=%d,errmsg=%s\n",errcode,errmsg);
9 | return true;
10 | }
11 |
12 | int main(int argc,char **argv)
13 | {
14 | DB_student studentdb;
15 | size_t size,inused;
16 | int errcode;
17 | int i;
18 | char errmsg[300];
19 | char name[20];
20 | char room[20];
21 |
22 | if (argc == 1)
23 | {
24 | printf("students [C][O]\n");
25 | return 0;
26 | }
27 | if (argv[1][0] =='C')
28 | {
29 | if (studentdb.Create(".","qzh",1000000) == false)
30 | {
31 | studentdb.GetLastError(&errcode,errmsg);
32 | printf("errcode=%d,errmsg=%s\n",errcode,errmsg);
33 | return 0;
34 | }
35 | studentdb.UnLockDb();
36 | }
37 | else if (argv[1][0] == 'O')
38 | {
39 | if (studentdb.Open(".","qzh",READWRITE,3519,false,0) == false)
40 | {
41 | studentdb.GetLastError(&errcode,errmsg);
42 | printf("errcode=%d,errmsg=%s\n",errcode,errmsg);
43 | return 0;
44 | }
45 | studentdb.UnLockDb();
46 | }
47 | else
48 | {
49 | printf("students [C][O]\n");
50 | return 0;
51 | }
52 | studentdb.SetErrorHandle(myerrhandle);
53 |
54 | TB_grade grade(studentdb.GetDBHandle());
55 |
56 | studentdb.BeginTransaction();
57 | for (i=0; i<100; i++)
58 | {
59 | grade.newrecord();
60 | grade.set_math(i);
61 | grade.set_Chinese(i);
62 | grade.set_english(i);
63 | sprintf(name,"%d",i % 13);
64 | sprintf(room,"%d",i % 16);
65 | grade.append(i,name,room);
66 | }
67 | studentdb.CommitTransaction();
68 |
69 | // List all records of the table
70 | studentdb.BeginTransaction();
71 | if (grade.lists())
72 | {
73 | if (grade.end())
74 | {
75 | grade.erase();
76 | }
77 |
78 | if (grade.find_by_nameclassroom("0","8",LARGE))
79 | {
80 | if(grade.end()) {
81 | do {
82 | printf("id=%d, name=%s\n",grade.get_id(), grade.get_name());
83 | } while(grade.prev());
84 | }
85 | }
86 | }
87 | studentdb.CommitTransaction();
88 |
89 | // Use index for range searching records in the table
90 | studentdb.BeginTransaction();
91 | if (grade.find_by_nameindex("12",LARGE_EQ))
92 | {
93 | if(grade.first()) {
94 | do
95 | {
96 | printf("FindByName >=\"12\": id=%d,name=%s,classroom=%s,math=%4.1f,chinese=%4.1f,english=%4.1f\n",
97 | grade.get_id(),grade.get_name(),grade.get_classroom(),
98 | grade.get_math(),grade.get_Chinese(),grade.get_english());
99 | } while(grade.next());
100 | }
101 | }
102 | else
103 | {
104 | printf("not found\n");
105 | }
106 | studentdb.CommitTransaction();
107 |
108 | grade.dump();
109 | printf("dbversion=%s\n",studentdb.DbVersion());
110 | printf("libversion=%s\n",studentdb.LibVersion());
111 | studentdb.GetMemoryInfo(size,inused);
112 | printf("size=%d,inused=%d\n",size,inused);
113 | getc(stdin);
114 | studentdb.Close();
115 | printf("closed\n");
116 | getc(stdin);
117 | return 0;
118 | }
119 |
--------------------------------------------------------------------------------
/ksmdb/tool/clripc.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | ###########################################################################################
4 | # clripc.sh
5 |
6 | # 功能:
7 | # 内存数据库系统资源清理工具脚本,用于清理进程异常崩溃后内存数据库遗留的系统资源,
8 | # 这些遗留资源包括文件、System V共享内存、System V信号量。
9 |
10 | # 用法:
11 | # 把脚本拷贝到内存数据库所在目录,确认脚本执行权限,执行脚本:
12 | # ./clripc.sh dbpath dbname
13 | # 例:
14 | # ./clripc.sh /rk_a_mdb riskmdb
15 |
16 | # 备注:
17 | # 1)单进程使用内存数据库(嵌入式模式)场合可用本工具。
18 | # 2)使用ksmdbmanage多业务进程非隔离模式场合,可用本工具。
19 | # 3)使用ksmdbmanage多业务进程隔离模式场合,本工具当前版本没有清理隔离模式特有的资源,
20 | # 这类资源的例子:000059C9_5A97950E_00000001.a0.sem
21 |
22 |
23 | let ftokkey=0
24 | resfilenames=(0)
25 | function ftok(){
26 |
27 | pathname=$1;
28 | proj_id=$2;
29 |
30 | if [ "${pathname:0:1}" != "/" ] ; then
31 |
32 | pathname=${PWD}/${pathname}
33 |
34 | fi
35 | if ! test -f ${pathname} ; then
36 |
37 | echo "No File Found![${pathname}]"
38 | exit 4
39 | fi
40 |
41 | str_st_ino=`stat --format='%i' "${pathname}" 2>/dev/null`;
42 | str_st_dev=`stat --format='%d' "${pathname}" 2>/dev/null`;
43 |
44 | if [ "x${str_st_ino}" = "x" -o "x${str_st_dev}" = "x" ] ; then
45 | return 1;
46 | fi
47 |
48 | let st_ino=${str_st_ino}
49 |
50 | let st_dev=${str_st_dev}
51 |
52 | let key1=${st_ino}\&16#FFFF
53 |
54 | let key2=${st_dev}\&16#FF
55 |
56 | let key2=${key2}\<\<16
57 |
58 | let key3=${proj_id}\&16#FF
59 |
60 | let key3=${key3}\<\<24
61 |
62 | let ftokkey=${key1}\|${key2}
63 |
64 | let ftokkey=${ftokkey}\|${key3}
65 |
66 | }
67 | function echohelp(){
68 |
69 | echo "ksmdb ipc resource clean up tool."
70 | echo "Usage:clripc dbpath dbname"
71 | exit 5
72 |
73 | }
74 |
75 | function clrres(){
76 |
77 | reskey=$1
78 | ipctype=$2
79 | for filename in ${resfilenames[@]}
80 | do
81 | projid=0
82 | while(($projid<10))
83 | do
84 | let ftokkey=0
85 | #ftok函数取得文件对应的key,存入${ftokkey}
86 | ftok "${filename}" "${projid}"
87 | filekey=`printf "0x%08x" ${ftokkey}`
88 | #DEBUG INFO:
89 | #printf "file: %s proid: %d, genarator key: %s\n" ${filename} ${projid} ${filekey}
90 | if [ $reskey = $filekey ]
91 | then
92 | if [ $ipctype = "M" ]
93 | then
94 | #shm resource clean up
95 | echo "clear shm: ipcrm -M ${reskey}"
96 | ipcrm -M $reskey
97 | else
98 | #sema resource clean up
99 | echo "clear sema: ipcrm -S ${reskey}"
100 | ipcrm -S $reskey
101 | fi
102 | return 0
103 | fi
104 |
105 | let projid=projid+1
106 | done
107 | done
108 | printf "## ipc resource key: %s is not ksmdb resource.\n" $reskey
109 |
110 | }
111 |
112 | ####################################################
113 | #
114 | # shell start up
115 | if [ $# -ne 2 ] ; then
116 | echohelp
117 | fi
118 |
119 | printf "ksmdb ipc resource clean up startup:\n"
120 |
121 | #根据参数给定的内存数据库名,生成资源文件数组
122 | dbpath=$1
123 | dbname=$2
124 | dbfilename=${dbpath}"//"${dbname}
125 |
126 | printf "target ksmdb is: dbpath=%s dbname=%s\n" $dbpath $dbname
127 |
128 | #事务相关自旋锁对应的文件
129 | spinfilename=${dbfilename}".lk"
130 | if test -f ${spinfilename} ; then
131 | resfilenames[0]=${spinfilename}
132 | fi
133 |
134 | #自旋锁相关的信号量对应的文件
135 | sema_r_1=${dbfilename}".1.r.s0.sem"
136 | if test -f ${sema_r_1} ; then
137 | resfilenames[1]=${sema_r_1}
138 | fi
139 |
140 | sema_w_1=${dbfilename}".1.w.s0.sem"
141 | if test -f ${sema_w_1} ; then
142 | resfilenames[2]=${sema_w_1}
143 | fi
144 |
145 | sema_r_2=${dbfilename}".2.r.s0.sem"
146 | if test -f ${sema_r_2} ; then
147 | resfilenames[3]=${sema_r_2}
148 | fi
149 |
150 | sema_w_2=${dbfilename}".2.w.s0.sem"
151 | if test -f ${sema_w_2} ; then
152 | resfilenames[4]=${sema_w_2}
153 | fi
154 |
155 | #事务信息存储shm对应的文件
156 | sessionctfilename=${dbfilename}"_session_shmname"
157 | if test -f ${sessionctfilename} ; then
158 | resfilenames[5]=${sessionctfilename}
159 | fi
160 |
161 | #内存数据库数据对应的资源文件
162 | i=7
163 | for datafile in $(ls ${dbpath}/${dbname}*.data)
164 | do
165 | resfilenames[$i]=${datafile}
166 | let i=i+1
167 | done
168 |
169 | echo "ksmdb files:--------------------------"
170 | for rsfile in ${resfilenames[*]}
171 | do
172 | echo "$rsfile"
173 | done
174 |
175 | OLDIFS=$IFS
176 | IFS=$'\n'
177 |
178 | for i in $(ipcs -m | grep 0x | awk '{print $1}')
179 | do
180 | printf "\n\n###########################################\n" $i
181 | printf "system shm ipc resource key: %s\n" $i
182 | clrres "${i}" "M"
183 | done
184 |
185 | for i in $(ipcs -s | grep 0x | awk '{print $1}')
186 | do
187 | printf "\n\n###########################################\n" $i
188 | printf "system sema ipc resource key: %s\n" $i
189 | clrres "${i}" "S"
190 | done
191 |
192 | IFS=$OLDIFS
193 |
194 | printf "clear ksmdb files:-------------------------------\n"
195 | for rsfile in ${resfilenames[*]}
196 | do
197 | echo "clear ksmdb files: rm -f ${rsfile}"
198 | rm -f $rsfile
199 | done
200 |
201 | printf "clear sem for handle mutex :-------------------------------\n"
202 | semname="sem."${dbname}
203 | echo "clear sem for handle mutex: rm -f /dev/shm/${semname}"
204 | rm -f /dev/shm/${semname}
205 |
206 |
207 |
208 |
209 |
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/Configure.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | false
6 |
7 |
8 | Ch
9 |
10 |
11 | 127.0.0.1
12 |
13 |
14 | 6000
15 |
16 |
17 | Maximized
18 |
19 |
20 | -8
21 |
22 |
23 | -8
24 |
25 |
26 | 1366
27 |
28 |
29 | 706
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | true
42 |
43 |
44 | 300
45 |
46 |
47 |
48 |
49 |
50 | 127.0.0.1
51 |
52 |
53 | 6011
54 |
55 |
56 | 635234066630548775
57 |
58 |
59 | true
60 |
61 |
62 |
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/Interop.Excel.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/Interop.Excel.dll
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/Interop.Office.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/Interop.Office.dll
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/Kingstar.Common.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/Kingstar.Common.dll
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/Kingstar.Core.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/Kingstar.Core.dll
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/Kingstar.Toolkits.Common.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/Kingstar.Toolkits.Common.dll
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/Kingstar.Toolkits.Controls.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/Kingstar.Toolkits.Controls.dll
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/Kingstar.Toolkits.Queue.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/Kingstar.Toolkits.Queue.dll
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/MemoryClient.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/MemoryClient.exe
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/boost_thread.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/boost_thread.dll
--------------------------------------------------------------------------------
/ksmdb/tool/memoryclient/ksmdbcli.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ksdbdev/ksmdb_eval/e145e45ba82ce8ecf1e446d8ebca18bed8a6930a/ksmdb/tool/memoryclient/ksmdbcli.dll
--------------------------------------------------------------------------------