2011-03-15 86 views
1

我尝试了this ESENT例如对于C++ developers.I有最新安装的Windows SDK,我使用十二月C++,我有我包括在C:\开发-CPP \包括。我曾尝试将esent.h复制到我的includes目录中,但仍然收到很多错误。这是整个代码。设置基本ESENT用于C++例如

#undef JET_VERSION 
#define JET_VERSION 0x0501 
#include <stdio.h> 
#include <string.h> 
#include <esent.h> 

int main(int argc, char * argv[]) { 
     JET_INSTANCE instance; 
     JET_SESID sesid; 
     JET_DBID dbid; 
     JET_TABLEID tableid; 

     JET_COLUMNDEF columndef = {0}; 
     JET_COLUMNID columnid; 

     // Initialize ESENT. Setting JET_paramCircularLog to 1 means ESENT will automatically 
     // delete unneeded logfiles. JetInit will inspect the logfiles to see if the last 
     // shutdown was clean. If it wasn't (e.g. the application crashed) recovery will be 
     // run automatically bringing the database to a consistent state. 
     Call(JetCreateInstance(&instance, "instance")); 
     Call(JetSetSystemParameter(&instance, JET_sesidNil, JET_paramCircularLog, 1, NULL)); 
     Call(JetInit(&instance)); 
     Call(JetBeginSession(instance, &sesid, 0, 0)); 

     // Create the database. To open an existing database use the JetAttachDatabase 
     // and JetOpenDatabase APIs 
     Call(JetCreateDatabase(sesid, "edbtest.db", 0, &dbid, JET_bitDbOverwriteExisting)); 

     // Create the table. Meta-data operations are transacted and can be performed concurrently. 
     // For example, one session can add a column to a table while another session is reading 
     // or updating records in the same table. 
     // This table has no indexes defined, so it will use the default sequential index. Indexes 
     // can be defined with the JetCreateIndex API. 
     Call(JetBeginTransaction(sesid)); 
     Call(JetCreateTable(sesid, dbid, "table", 0, 100, &tableid)); 
     columndef.cbStruct = sizeof(columndef); 
     columndef.coltyp = JET_coltypLongText; 
     columndef.cp = 1252; 
     Call(JetAddColumn(sesid, tableid, "column1", &columndef, NULL, 0, &columnid)); 
     Call(JetCommitTransaction(sesid, JET_bitCommitLazyFlush)); 

     // Insert a record. This table only has one column but a table can have slightly over 64,000 
     // columns defined. Unless a column is declared as fixed or variable it won't take any space 
     // in the record unless set. An individual record can have several hundred columns set at one 
     // time, the exact number depends on the database page size and the contents of the columns. 
     Call(JetBeginTransaction(sesid)); 
     Call(JetPrepareUpdate(sesid, tableid, JET_prepInsert)); 
     char * message = "Hello world"; 
     Call(JetSetColumn(sesid, tableid, columnid, message, strlen(message)+1, 0, NULL)); 
     Call(JetUpdate(sesid, tableid, NULL, 0, NULL)); 
     Call(JetCommitTransaction(sesid, 0)); // Use JetRollback() to abort the transaction 

     // Retrieve a column from the record. Here we move to the first record with JetMove. By using 
     // JetMoveNext it is possible to iterate through all records in a table. Use JetMakeKey and 
     // JetSeek to move to a particular record. 
     Call(JetMove(sesid, tableid, JET_MoveFirst, 0)); 
     char buffer[1024]; 
     Call(JetRetrieveColumn(sesid, tableid, columnid, buffer, sizeof(buffer), NULL, 0, NULL)); 
     printf("%s", buffer); 

     // Terminate ESENT. This performs a clean shutdown. 
     JetCloseTable(sesid, tableid); 
     JetEndSession(sesid, 0); 
     JetTerm(instance); 
     return 0; 
} 

我需要为我的代码编译成功吗?

这里有一些编译器错误:

g++.exe "C:\dev\esent-example.cpp" -o "C:\dev\esent-example.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" 
In file included from C:/Dev-Cpp/include/specstrings.h:11, 
from C:/Dev-Cpp/include/esent.h:27, 
from C:\dev\esent-example.cpp:5: 
C:/Dev-Cpp/include/sal.h:23:28: linux/spinlock.h: No such file or directory 
C:/Dev-Cpp/include/sal.h:25:21: asm/pal.h: No such file or directory 
+0

请发表你得到确切的错误,或者至少第一线10-20 - 我们真的不能猜测。 – Mat 2011-03-15 11:53:23

+0

下次请编辑您的问题,这在评论中完全不可读。 – Mat 2011-03-15 12:02:56

+0

在MSDN http://blogs.msdn.com/b/windowssdk/archive/2008/10/23/esent-extensible-storage-engine-api-in-the-windows-sdk.aspx它说,你只需要链接esent.lib和esent.h,在我看来,我将需要超过两个。它像一个文件需要一堆其他人。 – Gandalf 2011-03-15 12:13:37

回答

1

可扩展存储引擎API是很老。它的文档已经停用,它认为它在2001年已被弃用。头文件在SDK中仍然可用,仅用于支持遗留代码。

我可以让你的代码生成与Visual Studio。如果你真的想要这样做,那么使用MSVC编译器和Windows SDK的MSFT版本是明智的。你可以免费下载Visual Studio的C++ Express版本,它应该有你需要的一切来构建它。投入时间并不是一个好主意。

+0

我会尝试使用Visual studio.Does编译它,它意味着当API退役的ESE内蒙古科技退休?。我一直在阅读Laurion的博客,并回答了我最后的ESE question.There是一家致力于ESE在MSDN博客HTTP ://blogs.msdn.com/b/laurionb/。请解释为什么我不应该在ESE上投入时间,同时提供所有这些优秀的功能。 – Gandalf 2011-03-15 14:53:22

+0

这个博客确实表明它确实存在。它也提到没有人知道这一点:)这并不完全解释为什么文档已经退役,也许这就是为什么没有人知道。我不知道,我有64位esent.lib链接库,这通常是一个好兆头。 Visual Studio将会构建它,祝你好运。 – 2011-03-15 15:02:05

+0

谢谢你的见解。“它也提到没有人知道这个:)”,劳里安喜欢这个。 – Gandalf 2011-03-15 15:43:34