kexi
sqlitealter.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 {
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
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
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
00111 }
00112
00113 return cancelled;
00114 }
|