diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-07-22 14:33:21 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-07-22 14:33:21 +0200 |
commit | cea6fb57ac8c9a893c0f404fef6c1469f0b6222b (patch) | |
tree | fed8b6ffa8ea2cb6347ece69c0cb81003d0ccbf6 /odb/context.cxx | |
parent | 5f71c55a1c24c23af1eeb0d664922497a0e5c071 (diff) |
Next chunk of functionality
Add SQL language lexer. Implement MySQL type declaration parser.
Create sub-directories for databases, currently mysql and tracer.
Create MySQL-specific context.
Diffstat (limited to 'odb/context.cxx')
-rw-r--r-- | odb/context.cxx | 77 |
1 files changed, 12 insertions, 65 deletions
diff --git a/odb/context.cxx b/odb/context.cxx index eb0aa5d..15d1adb 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -87,79 +87,21 @@ namespace "xor", "xor_eq" }; - - struct type_map_entry - { - const char* const cxx_type; - const char* const db_type; - }; - - type_map_entry mysql_type_map[] = - { - {"bool", "TINYINT(1)"}, - - {"char", "TINYINT"}, - {"signed char", "TINYINT"}, - {"unsigned char", "TINYINT UNSIGNED"}, - - {"short int", "SMALLINT"}, - {"short unsigned int", "SMALLINT UNSIGNED"}, - - {"int", "INT"}, - {"unsigned int", "INT UNSIGNED"}, - - {"long int", "BIGINT"}, - {"long unsigned int", "BIGINT UNSIGNED"}, - - {"long long int", "BIGINT"}, - {"long long unsigned int", "BIGINT UNSIGNED"}, - - {"float", "FLOAT"}, - {"double", "DOUBLE"}, - - {"::std::string", "TEXT"} - }; } context:: context (ostream& os_, - semantics::unit& unit_, - options_type const& ops) - : data_ (new (shared) data), + semantics::unit& u, + options_type const& ops, + data_ptr d) + : data_ (d ? d : data_ptr (new (shared) data)), os (os_), - unit (unit_), + unit (u), options (ops), keyword_set (data_->keyword_set_) { for (size_t i (0); i < sizeof (keywords) / sizeof (char*); ++i) data_->keyword_set_.insert (keywords[i]); - - // Populate the C++ type to DB type map. - // - { - size_t n; - type_map_entry* p; - - switch (options.database ()) - { - case database::mysql: - { - p = mysql_type_map; - n = sizeof (mysql_type_map) / sizeof (type_map_entry); - break; - } - default: - { - p = 0; - n = 0; - break; - } - } - - for (size_t i (0); i < n; ++i) - data_->type_map_.insert ( - type_map_type::value_type (p[i].cxx_type, p[i].db_type)); - } } context:: @@ -172,6 +114,11 @@ context (context& c) { } +context:: +~context () +{ +} + string context:: table_name (semantics::type& t) const { @@ -209,7 +156,7 @@ column_name (semantics::data_member& m) const } string context:: -db_type (semantics::data_member& m) const +column_type (semantics::data_member& m) const { if (m.count ("type")) return m.get<string> ("type"); @@ -218,7 +165,7 @@ db_type (semantics::data_member& m) const type_map_type::const_iterator i (data_->type_map_.find (name)); if (i != data_->type_map_.end ()) - return i->second; + return m.count ("id") ? i->second.id_type : i->second.type; cerr << m.file () << ":" << m.line () << ":" << m.column () << " error: unable to map C++ type '" << name << "' used in " |