- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
TestSimpleAccess.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:2k
源码类别:
MySQL数据库
开发平台:
Visual C++
- /*-
- * See the file LICENSE for redistribution information.
- *
- * Copyright (c) 2000-2002
- * Sleepycat Software. All rights reserved.
- *
- * $Id: TestSimpleAccess.cpp,v 1.5 2002/01/23 14:26:41 bostic Exp $
- */
- /*
- * Do some regression tests for constructors.
- * Run normally (without arguments) it is a simple regression test.
- * Run with a numeric argument, it repeats the regression a number
- * of times, to try to determine if there are memory leaks.
- */
- #include <db_cxx.h>
- #include <iostream.h>
- int main(int argc, char *argv[])
- {
- try {
- Db *db = new Db(NULL, 0);
- db->open(NULL, "my.db", NULL, DB_BTREE, DB_CREATE, 0644);
- // populate our massive database.
- // all our strings include null for convenience.
- // Note we have to cast for idiomatic
- // usage, since newer gcc requires it.
- Dbt *keydbt = new Dbt((char *)"key", 4);
- Dbt *datadbt = new Dbt((char *)"data", 5);
- db->put(NULL, keydbt, datadbt, 0);
- // Now, retrieve. We could use keydbt over again,
- // but that wouldn't be typical in an application.
- Dbt *goodkeydbt = new Dbt((char *)"key", 4);
- Dbt *badkeydbt = new Dbt((char *)"badkey", 7);
- Dbt *resultdbt = new Dbt();
- resultdbt->set_flags(DB_DBT_MALLOC);
- int ret;
- if ((ret = db->get(NULL, goodkeydbt, resultdbt, 0)) != 0) {
- cout << "get: " << DbEnv::strerror(ret) << "n";
- }
- else {
- char *result = (char *)resultdbt->get_data();
- cout << "got data: " << result << "n";
- }
- if ((ret = db->get(NULL, badkeydbt, resultdbt, 0)) != 0) {
- // We expect this...
- cout << "get using bad key: "
- << DbEnv::strerror(ret) << "n";
- }
- else {
- char *result = (char *)resultdbt->get_data();
- cout << "*** got data using bad key!!: "
- << result << "n";
- }
- cout << "finished testn";
- }
- catch (DbException &dbe) {
- cerr << "Db Exception: " << dbe.what();
- }
- return 0;
- }