| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef APP_SQL_STATEMENT_H_ | 5 #ifndef APP_SQL_STATEMENT_H_ |
| 6 #define APP_SQL_STATEMENT_H_ | 6 #define APP_SQL_STATEMENT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "app/sql/connection.h" | 11 #include "app/sql/connection.h" |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "base/string16.h" |
| 14 | 15 |
| 15 namespace sql { | 16 namespace sql { |
| 16 | 17 |
| 17 // Possible return values from ColumnType in a statement. These should match | 18 // Possible return values from ColumnType in a statement. These should match |
| 18 // the values in sqlite3.h. | 19 // the values in sqlite3.h. |
| 19 enum ColType { | 20 enum ColType { |
| 20 COLUMN_TYPE_INTEGER = 1, | 21 COLUMN_TYPE_INTEGER = 1, |
| 21 COLUMN_TYPE_FLOAT = 2, | 22 COLUMN_TYPE_FLOAT = 2, |
| 22 COLUMN_TYPE_TEXT = 3, | 23 COLUMN_TYPE_TEXT = 3, |
| 23 COLUMN_TYPE_BLOB = 4, | 24 COLUMN_TYPE_BLOB = 4, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // may not always care about the return value (they'll DCHECK if they fail). | 98 // may not always care about the return value (they'll DCHECK if they fail). |
| 98 // The main thing you may want to check is when binding large blobs or | 99 // The main thing you may want to check is when binding large blobs or |
| 99 // strings there may be out of memory. | 100 // strings there may be out of memory. |
| 100 bool BindNull(int col); | 101 bool BindNull(int col); |
| 101 bool BindBool(int col, bool val); | 102 bool BindBool(int col, bool val); |
| 102 bool BindInt(int col, int val); | 103 bool BindInt(int col, int val); |
| 103 bool BindInt64(int col, int64 val); | 104 bool BindInt64(int col, int64 val); |
| 104 bool BindDouble(int col, double val); | 105 bool BindDouble(int col, double val); |
| 105 bool BindCString(int col, const char* val); | 106 bool BindCString(int col, const char* val); |
| 106 bool BindString(int col, const std::string& val); | 107 bool BindString(int col, const std::string& val); |
| 108 bool BindString16(int col, const string16& value); |
| 107 bool BindBlob(int col, const void* value, int value_len); | 109 bool BindBlob(int col, const void* value, int value_len); |
| 108 | 110 |
| 109 // Retrieving ---------------------------------------------------------------- | 111 // Retrieving ---------------------------------------------------------------- |
| 110 | 112 |
| 111 // Returns the number of output columns in the result. | 113 // Returns the number of output columns in the result. |
| 112 int ColumnCount() const; | 114 int ColumnCount() const; |
| 113 | 115 |
| 114 // Returns the type associated with the given column. | 116 // Returns the type associated with the given column. |
| 115 // | 117 // |
| 116 // Watch out: the type may be undefined if you've done something to cause a | 118 // Watch out: the type may be undefined if you've done something to cause a |
| 117 // "type conversion." This means requesting the value of a column of a type | 119 // "type conversion." This means requesting the value of a column of a type |
| 118 // where that type is not the native type. For safety, call ColumnType only | 120 // where that type is not the native type. For safety, call ColumnType only |
| 119 // on a column before getting the value out in any way. | 121 // on a column before getting the value out in any way. |
| 120 ColType ColumnType(int col) const; | 122 ColType ColumnType(int col) const; |
| 121 | 123 |
| 122 // These all take a 0-based argument index. | 124 // These all take a 0-based argument index. |
| 123 bool ColumnBool(int col) const; | 125 bool ColumnBool(int col) const; |
| 124 int ColumnInt(int col) const; | 126 int ColumnInt(int col) const; |
| 125 int64 ColumnInt64(int col) const; | 127 int64 ColumnInt64(int col) const; |
| 126 double ColumnDouble(int col) const; | 128 double ColumnDouble(int col) const; |
| 127 std::string ColumnString(int col) const; | 129 std::string ColumnString(int col) const; |
| 130 string16 ColumnString16(int col) const; |
| 128 | 131 |
| 129 // When reading a blob, you can get a raw pointer to the underlying data, | 132 // When reading a blob, you can get a raw pointer to the underlying data, |
| 130 // along with the length, or you can just ask us to copy the blob into a | 133 // along with the length, or you can just ask us to copy the blob into a |
| 131 // vector. Danger! ColumnBlob may return NULL if there is no data! | 134 // vector. Danger! ColumnBlob may return NULL if there is no data! |
| 132 int ColumnByteLength(int col) const; | 135 int ColumnByteLength(int col) const; |
| 133 const void* ColumnBlob(int col) const; | 136 const void* ColumnBlob(int col) const; |
| 137 bool ColumnBlobAsString(int col, std::string* blob); |
| 134 void ColumnBlobAsVector(int col, std::vector<char>* val) const; | 138 void ColumnBlobAsVector(int col, std::vector<char>* val) const; |
| 135 void ColumnBlobAsVector(int col, std::vector<unsigned char>* val) const; | 139 void ColumnBlobAsVector(int col, std::vector<unsigned char>* val) const; |
| 136 | 140 |
| 137 // Diagnostics -------------------------------------------------------------- | 141 // Diagnostics -------------------------------------------------------------- |
| 138 | 142 |
| 139 // Returns the original text of sql statement. Do not keep a pointer to it. | 143 // Returns the original text of sql statement. Do not keep a pointer to it. |
| 140 const char* GetSQLStatement(); | 144 const char* GetSQLStatement(); |
| 141 | 145 |
| 142 private: | 146 private: |
| 143 // This is intended to check for serious errors and report them to the | 147 // This is intended to check for serious errors and report them to the |
| 144 // connection object. It takes a sqlite error code, and returns the same | 148 // connection object. It takes a sqlite error code, and returns the same |
| 145 // code. Currently this function just updates the succeeded flag, but will be | 149 // code. Currently this function just updates the succeeded flag, but will be |
| 146 // enhanced in the future to do the notification. | 150 // enhanced in the future to do the notification. |
| 147 int CheckError(int err); | 151 int CheckError(int err); |
| 148 | 152 |
| 149 // The actual sqlite statement. This may be unique to us, or it may be cached | 153 // The actual sqlite statement. This may be unique to us, or it may be cached |
| 150 // by the connection, which is why it's refcounted. This pointer is | 154 // by the connection, which is why it's refcounted. This pointer is |
| 151 // guaranteed non-NULL. | 155 // guaranteed non-NULL. |
| 152 scoped_refptr<Connection::StatementRef> ref_; | 156 scoped_refptr<Connection::StatementRef> ref_; |
| 153 | 157 |
| 154 // See Succeeded() for what this holds. | 158 // See Succeeded() for what this holds. |
| 155 bool succeeded_; | 159 bool succeeded_; |
| 156 | 160 |
| 157 DISALLOW_COPY_AND_ASSIGN(Statement); | 161 DISALLOW_COPY_AND_ASSIGN(Statement); |
| 158 }; | 162 }; |
| 159 | 163 |
| 160 } // namespace sql | 164 } // namespace sql |
| 161 | 165 |
| 162 #endif // APP_SQL_STATEMENT_H_ | 166 #endif // APP_SQL_STATEMENT_H_ |
| OLD | NEW |