kexi

sqlitealter.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 // ** bits of SQLiteConnection related to table altering **
00021 
00022 #include "sqliteconnection.h"
00023 #include <kexidb/utils.h>
00024 
00025 #include <kstaticdeleter.h>
00026 
00027 #include <qmap.h>
00028 
00029 using namespace KexiDB;
00030 
00031 enum SQLiteTypeAffinity { //as defined here: 2.1 Determination Of Column Affinity (http://sqlite.org/datatype3.html)
00032     NoAffinity = 0, IntAffinity = 1, TextAffinity = 2, BLOBAffinity = 3
00033 };
00034 
00036 static KStaticDeleter< QMap<int,int> > KexiDB_SQLite_affinityForType_deleter;
00037 QMap<int,int> *KexiDB_SQLite_affinityForType = 0;
00038 
00041 static SQLiteTypeAffinity affinityForType(Field::Type type)
00042 {
00043     if (!KexiDB_SQLite_affinityForType) {
00044         KexiDB_SQLite_affinityForType_deleter.setObject( KexiDB_SQLite_affinityForType, new QMap<int,int>() );
00045         KexiDB_SQLite_affinityForType->insert(Field::Byte, IntAffinity);
00046         KexiDB_SQLite_affinityForType->insert(Field::ShortInteger, IntAffinity);
00047         KexiDB_SQLite_affinityForType->insert(Field::Integer, IntAffinity);
00048         KexiDB_SQLite_affinityForType->insert(Field::BigInteger, IntAffinity);
00049         KexiDB_SQLite_affinityForType->insert(Field::Boolean, IntAffinity);
00050         KexiDB_SQLite_affinityForType->insert(Field::Date, TextAffinity);
00051         KexiDB_SQLite_affinityForType->insert(Field::DateTime, TextAffinity);
00052         KexiDB_SQLite_affinityForType->insert(Field::Time, TextAffinity);
00053         KexiDB_SQLite_affinityForType->insert(Field::Float, IntAffinity);
00054         KexiDB_SQLite_affinityForType->insert(Field::Double, IntAffinity);
00055         KexiDB_SQLite_affinityForType->insert(Field::Text, TextAffinity);
00056         KexiDB_SQLite_affinityForType->insert(Field::LongText, TextAffinity);
00057         KexiDB_SQLite_affinityForType->insert(Field::BLOB, BLOBAffinity);
00058     }
00059     return static_cast<SQLiteTypeAffinity>((*KexiDB_SQLite_affinityForType)[(int)type]);
00060 }
00061 
00062 tristate SQLiteConnection::drv_changeFieldProperty(TableSchema &table, Field& field, 
00063     const QString& propertyName, const QVariant& value)
00064 {
00065 /*  if (propertyName=="name") {
00066         
00067     }*/
00068     if (propertyName=="type") {
00069         bool ok;
00070         Field::Type type = KexiDB::intToFieldType( value.toUInt(&ok) );
00071         if (!ok || Field::InvalidType == type) {
00073             return false;
00074         }
00075         return changeFieldType(table, field, type);
00076     }
00077     // not found
00078     return cancelled;
00079 }
00080 
00102 tristate SQLiteConnection::changeFieldType(TableSchema &table, Field& field, 
00103     Field::Type type)
00104 {
00105     Q_UNUSED(table);
00106     const Field::Type oldType = field.type();
00107     const SQLiteTypeAffinity oldAffinity = affinityForType(oldType);
00108     const SQLiteTypeAffinity newAffinity = affinityForType(type);
00109     if (oldAffinity!=newAffinity) {
00110         //type affinity will be changed
00111     }
00112 
00113     return cancelled;
00114 }
KDE Home | KDE Accessibility Home | Description of Access Keys