gpt4 book ai didi

c++ - 为 C++ 示例设置基本 Esent

转载 作者:太空宇宙 更新时间:2023-11-04 04:06:35 25 4
gpt4 key购买 nike

我正在尝试 this C++ 开发人员的 esent 示例。我安装了最新的 Windows SDK,我正在使用 Dec C++。我在 C:\Dev-Cpp\include 中有我的包含。我尝试将 esent.h 复制到我的包含目录,但我仍然很很多错误。这是完整的代码。

#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

最佳答案

Extensible Storage Engine api 很旧。它的文档已经停用,它认为它早在 2001 年就被弃用了。头文件在 SDK 中仍然可用,只是为了支持遗留代码。

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

关于c++ - 为 C++ 示例设置基本 Esent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5311252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com