[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    [Kde-pim] [patch] smale patch for
From:       Tony Wolf <wolf () os-forge ! net>
Date:       2008-03-28 21:47:02
Message-ID: 47ED6756.90303 () os-forge ! net
[Download RAW message or body]

Hi everybody,

I've done my second patch on 
akonadi/server/src/storage/dbinitializer.cpp. It provides some chances 
for PSQL support as requested on [1].

It compiles and seems to work. I started akonadiserver, once without db 
and once with already existing db. Also I import a ical-resouce.

Also I delete

while ( query.next() ) {
     // FIXME: use column name (key_name) instead of column index!!
     if ( query.value(2) == indexName )
       return true;
   }

and source it out in the sql-statement (both, MySQL and PSQL).

Please review it as I try to match your coding-style. I hope, that I 
haven't forgot a rule. :D


Best regards

Tony

["dbinitializer.cpp.patch" (text/x-diff)]

Index: akonadi/server/src/storage/dbinitializer.cpp
===================================================================
--- akonadi/server/src/storage/dbinitializer.cpp	(Revision 791220)
+++ akonadi/server/src/storage/dbinitializer.cpp	(Arbeitskopie)
@@ -212,7 +212,7 @@
         statement += tableName;
         statement += QLatin1String( " (" );
         statement += columnElement.attribute( QLatin1String("columns") );
-        statement += QLatin1Char(')');
+        statement += QLatin1String(");");
         QSqlQuery query( mDatabase );
         qDebug() << "adding index" << statement;
         if ( !query.exec( statement ) ) {
@@ -308,7 +308,9 @@
   if ( type == QLatin1String("QString") )
     return QLatin1String("TEXT");
   if (type == QLatin1String("QByteArray") )
-    return QLatin1String("LONGBLOB");
+    return ( mDatabase.driverName() == QLatin1String("QPSQL") )
+            ? QLatin1String("BYTEA")
+            : QLatin1String("LONGBLOB");
   if ( type == QLatin1String("QDateTime") )
     return QLatin1String("TIMESTAMP");
   if ( type == QLatin1String( "bool" ) )
@@ -344,21 +346,24 @@
 
 bool DbInitializer::hasIndex(const QString & tableName, const QString & indexName)
 {
+  // create statement
+QString statement;
   if ( mDatabase.driverName().startsWith( QLatin1String("QMYSQL") ) ) {
-    QString statement = QString::fromLatin1("SHOW INDEXES FROM %1").arg( tableName \
                );
-    QSqlQuery query( mDatabase );
-    if ( !query.exec( statement ) ) {
-      mErrorMsg = QLatin1String( "Unable to list index information." );
-      return false;
-    }
-    while ( query.next() ) {
-      // FIXME: use column name (key_name) instead of column index!!
-      if ( query.value(2) == indexName )
-        return true;
-    }
-    return false;
+    statement  = QString::fromLatin1( "SHOW INDEXES FROM %1" ).arg( tableName );
+    statement += QString::fromLatin1( " WHERE `Key_name` LIKE '%1'" ).arg( indexName \
); +  } else if( mDatabase.driverName() == QLatin1String("PSQL") ) {
+    statement  = QLatin1String( "SELECT indexname FROM pq_indexes" );
+    statement += QString::fromLatin1( " WHERE tablename = '%1'" ).arg( tableName );
+    statement += QString::fromLatin1( " AND  indexname = '%1';" ).arg( indexName );
   } else {
-    qFatal("Implement index support for your database!");
+    qFatal( "Implement index support for your database!" );
   }
-  return false;
+
+  // query it
+  QSqlQuery query( mDatabase );
+  if ( !query.exec( statement ) ) {
+    mErrorMsg = QString::fromLatin1( "Unable to list index information for table \
%1." ).arg( tableName ); +    return false;
+  }
+  return query.next();
 }



_______________________________________________
KDE PIM mailing list kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic