UniSet  1.7.0
DBInterface.h
См. документацию.
00001 /* This file is part of the UniSet project
00002  * Copyright (c) 2002 Free Software Foundation, Inc.
00003  * Copyright (c) 2002 Pavel Vainerman
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018  */
00019 // --------------------------------------------------------------------------
00023 //----------------------------------------------------------------------------
00024 #ifndef DBInterface_H_
00025 #define DBInterface_H_
00026 // ---------------------------------------------------------------------------
00027 #include <string>
00028 #include <iostream>
00029 //#warning Для использования mysql_create нужен define USE_OLD_FUNCTIONS
00030 //#define USE_OLD_FUNCTIONS
00031 #include <mysql/mysql.h>
00032 // ----------------------------------------------------------------------------
00033 class DBInterface
00034 {
00035     public:
00036     
00037             DBInterface();
00038             ~DBInterface();
00039 
00040 //          bool createDB(const std::string dbname);
00041 //          bool dropDB(const std::string dbname);
00042             MYSQL_RES * listFields(const std::string& table, const std::string& wild );
00043 
00044 
00045             bool connect( const std::string& host, const std::string& user, const std::string& pswd,
00046                             const std::string& dbname);
00047             bool close();
00048             
00049             bool query(const std::string& q);
00050             bool query( const char* q, bool noLastQ=false ); // noLastQ - не запоминать запрос
00051 
00052             const std::string lastQuery();
00053             bool insert(const std::string& q);
00054 
00055             std::string addslashes(const std::string& str);
00056             
00061             bool ping();
00062 
00064             bool isConnection();
00065             
00066             bool nextRecord();
00067             void freeResult();
00068 
00069             unsigned int numCols();
00070             unsigned int numRows();
00071 
00072             bool moveToRow(int ind);
00073             
00074             int insert_id();
00075 
00076             const MYSQL_ROW getRow();
00077             const std::string error();
00078             
00079             MYSQL_ROW Row;
00080 
00081             // *******************
00082             const char* gethostinfo();
00083     protected:
00084     
00085     private:
00086     
00087         MYSQL_RES *result;
00088         MYSQL *mysql;
00089         std::string lastQ;
00090         bool queryok;   // успешность текущего запроса
00091         bool connected;
00092 };
00093 // ----------------------------------------------------------------------------------
00094 #endif