/usr/include/Wt/Dbo/SqlConnection is in libwtdbo-dev 3.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WT_DBO_SQL_CONNECTION_H_
#define WT_DBO_SQL_CONNECTION_H_
#include <map>
#include <string>
#include <vector>
#include <Wt/Dbo/WDboDllDefs.h>
namespace Wt {
namespace Dbo {
/*! \brief Enum that defines a date time type.
*/
enum SqlDateTimeType {
SqlDate, //!< Date only
SqlDateTime,//!< Date and time
SqlTime //!< Time duration
};
class SqlStatement;
/*! \class SqlConnection Wt/Dbo/SqlConnection Wt/Dbo/SqlConnection
* \brief Abstract base class for an SQL connection.
*
* An sql connection manages a single connection to a database. It
* also manages a map of previously prepared statements indexed by
* id's.
*
* This class is part of Wt::Dbo's backend API, and should not be used
* directly.
*
* \ingroup dbo
*/
class WTDBO_API SqlConnection
{
public:
/*! \brief Destructor.
*/
virtual ~SqlConnection();
/*! \brief Clones the connection.
*
* Returns a new connection object that is configured like this
* object. This is used by connection pool implementations to create
* its connections.
*/
virtual SqlConnection *clone() const = 0;
/*! \brief Executes an SQL statement.
*
* This is a convenience method for preparing a statement, executing
* it, and deleting it.
*/
virtual void executeSql(const std::string& sql);
/*! \brief Starts a transaction
*
* This function starts a transaction.
*/
virtual void startTransaction() = 0;
/*! \brief Commits a transaction
*
* This function commits a transaction.
*/
virtual void commitTransaction() = 0;
/*! \brief Rolls back a transaction
*
* This function rolls back a transaction.
*/
virtual void rollbackTransaction() = 0;
/*! \brief Returns the statement with the given id.
*
* Returns 0 if no such statement was already added.
*
* \sa saveStatement()
*/
virtual SqlStatement *getStatement(const std::string& id) const;
/*! \brief Saves a statement with the given id.
*
* Saves the statement for future reuse using getStatement()
*/
virtual void saveStatement(const std::string& id,
SqlStatement *statement);
/*! \brief Prepares a statement.
*
* Returns the prepared statement.
*/
virtual SqlStatement *prepareStatement(const std::string& sql) = 0;
/*! \brief Sets a property.
*
* Properties may tailor the backend behavior. Some properties are
* applicable to all backends, while some are backend specific.
*
* General properties are:
* - <tt>show-queries</tt>: when value is "true", queries are shown
* as they are executed.
*/
void setProperty(const std::string& name, const std::string& value);
/*! \brief Returns a property.
*
* Returns the property value, or an empty string if the property was
* not set.
*
* \sa setProperty()
*/
std::string property(const std::string& name) const;
/** @name Methods that return dialect information
*/
//@{
/*! \brief Returns the 'autoincrement' SQL type modifier.
*
* This is used by Session::createTables() to create the <i>id</i>
* column.
*/
virtual std::string autoincrementSql() const = 0;
/*! \brief Returns the SQL statement(s) required to create an id sequence.
*
* This is used by Session::createTables() to create the id
* sequence for a table.
* The table's name and primary key are passed as arguments to this function
* and can be used to construct an SQL sequence that is unique for the table.
*/
virtual std::vector<std::string>
autoincrementCreateSequenceSql(const std::string &table,
const std::string &id) const = 0;
/*! \brief Returns the SQL statement(s) required to drop an id sequence.
*
* This is used by Session::dropTables() to drop the id sequence for a table.
* The table's name and primary key are passed as arguments to this function
* and can be used to construct an SQL sequence that is unique for the table.
*/
virtual std::vector<std::string>
autoincrementDropSequenceSql(const std::string &table,
const std::string &id) const = 0;
/*! \brief Returns the 'autoincrement' SQL type.
*
* This is used by Session::createTables() to create the <i>id</i>
* column.
*/
virtual std::string autoincrementType() const = 0;
/*! \brief Returns the suffix for an 'autoincrement' insert statement.
*
* This is appended to the <tt>insert</tt> statement, since some back-ends
* need to be indicated that they should return the autoincrement id.
*/
virtual std::string autoincrementInsertSuffix() const = 0;
/*! \brief Execute code before dropping the tables.
*
* This method is called before calling Session::dropTables().
* The default implementation is empty.
*/
virtual void prepareForDropTables();
/*! \brief Returns the date/time type.
*
* \sa SqlStatement::bind(int, const boost::posix_time::ptime&, SqlDateTimeType)
*/
virtual const char *dateTimeType(SqlDateTimeType type) const = 0;
/*! \brief Returns the blob type.
*
* \sa SqlStatement::bind(int, const std::vector<unsigned char>&)
*/
virtual const char *blobType() const = 0;
/*! \brief Returns the text type.
*
* This method will return "text" by default.
*
* \sa SqlStatement::bind(int column, const std::string& value)
*/
virtual const char *textType() const;
/*! \brief Returns the boolean type.
*
* This method will return "boolean" by default.
*/
virtual const char *booleanType() const;
/*! \brief Returns whether the SQL dialect uses 'ROWS ? TO ?' for partial
* select results.
*
* This is an alternative SQL dialect option to the (non-standard) 'OFFSET ?
* LIMIT ?' syntax.
*
* The default implementation returns \c false.
*/
virtual bool usesRowsFromTo() const;
/*! \brief Returns true if the backend support Alter Table
*
* This method will return false by default.
*/
virtual bool supportAlterTable() const;
/*! \brief Returns the command used in alter table .. drop constraint ..
*
* This method will return "constraint" by default.
* Default: ALTER TABLE .. DROP CONSTRAINT ..
*/
virtual const char *alterTableConstraintString() const;
//@}
bool showQueries() const;
protected:
SqlConnection();
SqlConnection(const SqlConnection& other);
void clearStatementCache();
private:
typedef std::map<std::string, SqlStatement *> StatementMap;
StatementMap statementCache_;
std::map<std::string, std::string> properties_;
};
}
}
#endif // WT_DBO_SQL_STATEMENT_H_
|