Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Column.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file basic/database/schema_generator/Column.cc
11 ///
12 /// @brief Column class for the schema generator framework
13 /// @author Tim Jacobs
14 
15 //Unit Headers
18 
19 // Utility Headers
20 #include <utility/exit.hh>
23 
24 namespace basic {
25 namespace database {
26 namespace schema_generator {
27 
29  name_(name),
30  type_(type),
31  allow_null_(true),
32  auto_increment_(false),
33  auto_increment_base_(0)
34 {}
35 
36 Column::Column(std::string name, DbDataTypeOP type, bool allow_null) :
37  name_(name),
38  type_(type),
39  allow_null_(allow_null),
40  auto_increment_(false),
41  auto_increment_base_(0)
42 {}
43 
44 Column::Column(std::string name, DbDataTypeOP type, bool allow_null, bool auto_increment, platform::Size auto_increment_base) :
45  name_(name),
46  type_(type),
47  allow_null_(allow_null),
48  auto_increment_(auto_increment),
49  auto_increment_base_(auto_increment_base)
50 {}
51 
52 Column::Column(Column const & src) :
53  ReferenceCount(),
54  name_(src.name_),
55  type_(src.type_),
56  allow_null_(src.allow_null_),
57  auto_increment_(src.auto_increment_),
58  auto_increment_base_(src.auto_increment_base_)
59 {}
60 
62 
63 std::string Column::name() const{
64  return name_;
65 }
66 
68  return this->auto_increment_;
69 }
70 
72  return this->auto_increment_base_;
73 }
74 
75 std::string Column::print(utility::sql_database::sessionOP db_session) const{
76  std::string column_string = "";
77  if ( auto_increment_ ) {
78  column_string += name_ + " ";
79  switch(db_session->get_db_mode()) {
81  column_string += this->type_->print(db_session) + " PRIMARY KEY AUTOINCREMENT"; //only way to autoincrement in SQLite is with a primary key
82  name_ + " " + type_->print(db_session);
83  break;
85  column_string += this->type_->print(db_session) + " AUTO_INCREMENT";
86  break;
88  column_string += "BIGSERIAL";
89  break;
90  default :
91  utility_exit_with_message("ERROR:Please specify the database mode using -inout::dbms::mode. Valid options are: 'sqlite3', 'mysql', or 'postgres'");
92  }
93  } else {
94  column_string += this->name_ + " " + this->type_->print(db_session);
95  }
96 
97  if ( !allow_null_ ) {
98  column_string += " NOT NULL";
99  }
100  return column_string;
101 }
102 
103 bool Column::operator==(const Column &other) const {
104  return (this->name_.compare(other.name()) == 0);
105 }
106 
107 } // schema_generator
108 } // namespace database
109 } // namespace utility
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
std::string print(utility::sql_database::sessionOP db_session) const
Definition: Column.cc:75
tuple database
Program exit functions and macros.
bool operator==(const Column &other) const
Definition: Column.cc:103
Column class for the schema generator framework.
rule< Scanner, string_closure::context_t > name
Definition: Tag.cc:376
Column(std::string name, DbDataTypeOP type)
Definition: Column.cc:28
std::size_t Size
Definition: types.hh:37
pointer::shared_ptr< session > sessionOP
utility::pointer::shared_ptr< DbDataType > DbDataTypeOP