Index: sql/connection.cc |
diff --git a/sql/connection.cc b/sql/connection.cc |
index ea3dacbb6ba025dc248590a40031cc4a508541f4..ac19d4c8fdde1518854cfc4628cbf52d37c46ca8 100644 |
--- a/sql/connection.cc |
+++ b/sql/connection.cc |
@@ -11,8 +11,8 @@ |
#include "base/string_util.h" |
#include "base/stringprintf.h" |
#include "base/utf_string_conversions.h" |
-#include "sql/statement.h" |
#include "third_party/sqlite/sqlite3.h" |
+#include "sql/statement.h" |
rlarocque
2012/10/01 21:45:55
This should be in alphabetical order.
vishwath
2012/10/02 01:06:33
Done.
|
namespace { |
@@ -455,6 +455,29 @@ bool Connection::DoesColumnExist(const char* table_name, |
return false; |
} |
+ColType Connection::GetColumnType(char* table_name, |
+ int column_index) const { |
+ std::string sql("PRAGMA TABLE INFO("); |
+ sql.append(table_name); |
+ sql.append(")"); |
+ |
+ Statement statement(GetUntrackedStatement(sql.c_str())); |
+ for(int i = 0; i <= column_index; i++) |
+ statement.Step(); |
+ |
+ std::string column_type = statement.ColumnString(2); |
rlarocque
2012/10/01 21:45:55
When I suggested the PRAGMA TABLE INFO, it didn't
vishwath
2012/10/02 01:06:33
It turns out that the returned information is of a
rlarocque
2012/10/02 01:39:50
Not quite what I had in mind, but that looks OK.
|
+ if(column_type == "INTEGER") |
+ return COLUMN_TYPE_INTEGER; |
+ else if(column_type == "FLOAT") |
+ return COLUMN_TYPE_FLOAT; |
+ else if(column_type == "TEXT") |
+ return COLUMN_TYPE_TEXT; |
+ else if(column_type == "BLOB") |
+ return COLUMN_TYPE_BLOB; |
+ |
+ return COLUMN_TYPE_NULL; |
+} |
+ |
int64 Connection::GetLastInsertRowId() const { |
if (!db_) { |
DLOG(FATAL) << "Illegal use of connection without a db"; |