servlib/storage/PostgresSQLImplementation.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2004-2006 Intel Corporation
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifndef _POSTGRES_SQL_IMPLEMENTATION_H_
       
    18 #define _POSTGRES_SQL_IMPLEMENTATION_H_
       
    19 
       
    20 #include <libpq-fe.h>
       
    21 #include <oasys/debug/Log.h>
       
    22 #include <oasys/serialize/SQLImplementation.h>
       
    23 
       
    24 namespace dtn {
       
    25 
       
    26 /**
       
    27  * Postgres based implementation of SQL database.
       
    28  */
       
    29 class PostgresSQLImplementation : public oasys::SQLImplementation, public oasys::Logger {
       
    30 public:
       
    31     PostgresSQLImplementation();
       
    32     
       
    33     ///@{
       
    34     /// Virtual functions inherited from SQLImplementation
       
    35     int connect(const char* dbname);
       
    36     int close();
       
    37     bool has_table(const char* tablename);
       
    38     int exec_query(const char* query);
       
    39     int num_tuples();
       
    40     const char* get_value(int tuple_no, int field_no);
       
    41 //    size_t get_value_length(int tuple_no, int field_no);
       
    42     
       
    43 
       
    44     const char* escape_string(const char* from);
       
    45     const u_char* escape_binary(const u_char* from, int from_length);
       
    46     const u_char* unescape_binary(const u_char* from);
       
    47   
       
    48     ///@}
       
    49 
       
    50 private:
       
    51     PGconn* db_;  		///< the db connection
       
    52     PGresult* query_result_;	/// result of the last query performed
       
    53 };
       
    54 } // namespace dtn
       
    55 
       
    56 #endif /* _POSTGRES_SQL_IMPLEMENTATION_H_ */