1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
28 #include "StringUtilities.h"
30 TableDef::TableDef(std::string name
) :
34 std::string foreignname
;
35 foreignname
.append("fk");
37 std::string tablename
= name
;
38 char first
= tablename
[0];
39 first
= toupper(first
);
42 foreignname
.append(tablename
);
44 m_foreignname
= foreignname
;
52 cstring
TableDef::getName() const
57 void TableDef::addPK(const std::string
& name
)
59 FieldDefPtr
field(new KeyDef(shared_from_this(), name
, true));
60 m_deffields
.push_back(field
);
64 void TableDef::addFPK(TableDefPtr table
)
67 addFPK(table
, Global::Get()->EmptyString
);
70 void TableDef::addFPK(TableDefPtr table
, const std::string
& suffix
)
75 name
.append(table
->tableForeignName());
78 FieldDefPtr
field(new KeyDef(table
, name
, true));
79 m_deffields
.push_back(field
);
83 void TableDef::addValue(const std::string
& name
)
85 FieldDefPtr
field(new FieldDef(name
, false));
86 m_deffields
.push_back(field
);
89 void TableDef::addValue(const std::string
& name
, value_type defaultvalue
)
91 FieldDefPtr
field(new FieldDef(name
, false, String::Get()->fromInt(defaultvalue
)));
92 m_deffields
.push_back(field
);
95 void TableDef::addTextField(const std::string
& name
)
97 FieldDefPtr
field(new FieldDef(name
, true));
98 m_deffields
.push_back(field
);
101 void TableDef::addLookupTextField(const std::string
& name
)
103 FieldDefPtr
field(new FieldDef(name
, true, true));
104 m_deffields
.push_back(field
);
107 void TableDef::addTextField(const std::string
& name
, const std::string
& defaulttext
)
109 FieldDefPtr
field(new FieldDef(name
, true, defaulttext
));
110 m_deffields
.push_back(field
);
113 void TableDef::addFK(TableDefPtr table
)
117 addFK(table
, Global::Get()->EmptyString
);
120 void TableDef::addFK(TableDefPtr table
, const std::string
& suffix
)
125 name
.append(table
->tableForeignName());
128 FieldDefPtr
field(new KeyDef(table
, name
, false));
129 m_deffields
.push_back(field
);
130 // TODO, add SQLite triggers
133 const std::string
& TableDef::tableForeignName() const
135 return m_foreignname
;