sqlite/sqlitealter.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20// ** bits of SQLiteConnection related to table altering **
21
22#include "sqliteconnection.h"
23#include <kexidb/utils.h>
24
25#include <kstaticdeleter.h>
26
27#include <tqmap.h>
28
29using namespace KexiDB;
30
31enum SQLiteTypeAffinity { //as defined here: 2.1 Determination Of Column Affinity (http://sqlite.org/datatype3.html)
32 NoAffinity = 0, IntAffinity = 1, TextAffinity = 2, BLOBAffinity = 3
33};
34
36static KStaticDeleter< TQMap<int,int> > KexiDB_SQLite_affinityForType_deleter;
37TQMap<int,int> *KexiDB_SQLite_affinityForType = 0;
38
41static SQLiteTypeAffinity affinityForType(Field::Type type)
42{
43 if (!KexiDB_SQLite_affinityForType) {
44 KexiDB_SQLite_affinityForType_deleter.setObject( KexiDB_SQLite_affinityForType, new TQMap<int,int>() );
45 KexiDB_SQLite_affinityForType->insert(Field::Byte, IntAffinity);
46 KexiDB_SQLite_affinityForType->insert(Field::ShortInteger, IntAffinity);
47 KexiDB_SQLite_affinityForType->insert(Field::Integer, IntAffinity);
48 KexiDB_SQLite_affinityForType->insert(Field::BigInteger, IntAffinity);
49 KexiDB_SQLite_affinityForType->insert(Field::Boolean, IntAffinity);
50 KexiDB_SQLite_affinityForType->insert(Field::Date, TextAffinity);
51 KexiDB_SQLite_affinityForType->insert(Field::DateTime, TextAffinity);
52 KexiDB_SQLite_affinityForType->insert(Field::Time, TextAffinity);
53 KexiDB_SQLite_affinityForType->insert(Field::Float, IntAffinity);
54 KexiDB_SQLite_affinityForType->insert(Field::Double, IntAffinity);
55 KexiDB_SQLite_affinityForType->insert(Field::Text, TextAffinity);
56 KexiDB_SQLite_affinityForType->insert(Field::LongText, TextAffinity);
57 KexiDB_SQLite_affinityForType->insert(Field::BLOB, BLOBAffinity);
58 }
59 return static_cast<SQLiteTypeAffinity>((*KexiDB_SQLite_affinityForType)[(int)type]);
60}
61
63 const TQString& propertyName, const TQVariant& value)
64{
65/* if (propertyName=="name") {
66
67 }*/
68 if (propertyName=="type") {
69 bool ok;
70 Field::Type type = KexiDB::intToFieldType( value.toUInt(&ok) );
71 if (!ok || Field::InvalidType == type) {
73 return false;
74 }
75 return changeFieldType(table, field, type);
76 }
77 // not found
78 return cancelled;
79}
80
103 Field::Type type)
104{
105 Q_UNUSED(table);
106 const Field::Type oldType = field.type();
107 const SQLiteTypeAffinity oldAffinity = affinityForType(oldType);
108 const SQLiteTypeAffinity newAffinity = affinityForType(type);
109 if (oldAffinity!=newAffinity) {
110 //type affinity will be changed
111 }
112
113 return cancelled;
114}
Meta-data for a field.
Definition field.h:73
Type type() const
Definition field.cpp:134
@ ShortInteger
Definition field.h:86
@ InvalidType
Definition field.h:84
virtual tristate drv_changeFieldProperty(TableSchema &table, Field &field, const TQString &propertyName, const TQVariant &value)
tristate changeFieldType(TableSchema &table, Field &field, Field::Type type)
for drv_changeFieldProperty()
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition tristate.h:100
High-level database connectivity library with database backend drivers.
KEXI_DB_EXPORT Field::Type intToFieldType(int type)