Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: akonadi/server/src/storage/entities-source.xsl
- ===================================================================
- --- akonadi/server/src/storage/entities-source.xsl (revision 977078)
- +++ akonadi/server/src/storage/entities-source.xsl (working copy)
- @@ -237,7 +237,8 @@
- while ( query.next() ) {
- rv.append( <xsl:value-of select="$className"/>(
- <xsl:for-each select="column">
- - query.value( <xsl:value-of select="position() - 1"/> ).value<<xsl:value-of select="@type"/>>()
- + (query.isNull(<xsl:value-of select="position() - 1"/>)) ? <xsl:value-of select="@type"/>() :
- + query.value( <xsl:value-of select="position() - 1"/> ).value<<xsl:value-of select="@type"/>>()
- <xsl:if test="position() != last()">,</xsl:if>
- </xsl:for-each>
- ) );
- @@ -249,6 +250,7 @@
- <xsl:if test="column[@name='id']">
- <xsl:value-of select="$className"/><xsl:text> </xsl:text><xsl:value-of select="$className"/>::retrieveById( qint64 id )
- {
- + qDebug() << " :: RETRIEVE BY ID :: " << id;
- <xsl:call-template name="data-retrieval">
- <xsl:with-param name="key">id</xsl:with-param>
- <xsl:with-param name="cache">idCache</xsl:with-param>
- @@ -268,6 +270,8 @@
- QList<<xsl:value-of select="$className"/>> <xsl:value-of select="$className"/>::retrieveAll()
- {
- + qDebug() << "::: Retrieve ALL ";
- +
- QSqlDatabase db = DataStore::self()->database();
- if ( !db.isOpen() )
- return QList<<xsl:value-of select="$className"/>>();
- @@ -286,6 +290,7 @@
- QList<<xsl:value-of select="$className"/>> <xsl:value-of select="$className"/>::retrieveFiltered( const QString &key, const QVariant &value )
- {
- + qDebug() << "::::: RETRIEVE FILTERED " << key;
- QSqlDatabase db = DataStore::self()->database();
- if ( !db.isOpen() )
- return QList<<xsl:value-of select="$className"/>>();
- @@ -295,7 +300,10 @@
- statement.append( tableName() );
- statement.append( QLatin1String(" WHERE ") );
- statement.append( key );
- - statement.append( QLatin1String(" = :key") );
- + if ( value.isNull() )
- + statement.append( QLatin1String(" is null") );
- + else
- + statement.append( QLatin1String(" = :key") );
- query.prepare( statement );
- query.bindValue( QLatin1String(":key"), value );
- if ( !query.exec() ) {
- @@ -425,20 +433,38 @@
- QStringList cols, vals;
- <xsl:for-each select="column[@name != 'id']">
- - if ( d-><xsl:value-of select="@name"/>_changed ) {
- - cols.append( <xsl:value-of select="@name"/>Column() );
- - vals.append( QLatin1String( ":<xsl:value-of select="@name"/>" ) );
- - }
- + <xsl:variable name="refColumn"><xsl:value-of select="@refColumn"/></xsl:variable>
- + <xsl:if test="$refColumn = 'id'">
- + if ( d-><xsl:value-of select="@name"/>_changed && d-><xsl:value-of select="@name"/> > 0 ) {
- + cols.append( <xsl:value-of select="@name"/>Column() );
- + vals.append( QLatin1String( ":<xsl:value-of select="@name"/>" ) );
- + }
- + </xsl:if>
- + <xsl:if test="$refColumn != 'id'">
- + if ( d-><xsl:value-of select="@name"/>_changed ) {
- + cols.append( <xsl:value-of select="@name"/>Column() );
- + vals.append( QLatin1String( ":<xsl:value-of select="@name"/>" ) );
- + }
- + </xsl:if>
- </xsl:for-each>
- - QString statement = QString::fromLatin1("INSERT INTO <xsl:value-of select="$tableName"/> (%1) VALUES (%2)")
- - .arg( cols.join( QLatin1String(",") ), vals.join( QLatin1String(",") ) );
- + QString statement = QString::fromLatin1("INSERT INTO <xsl:value-of select="$tableName"/> (%1) VALUES (%2) %3")
- + .arg( cols.join( QLatin1String(",") ), vals.join( QLatin1String(",") ), QLatin1String(" RETURNING id") );
- +
- QSqlQuery query( db );
- query.prepare( statement );
- <xsl:for-each select="column[@name != 'id']">
- - if ( d-><xsl:value-of select="@name"/>_changed ) {
- - query.bindValue( QLatin1String(":<xsl:value-of select="@name"/>"), this-><xsl:value-of select="@name"/>() );
- - }
- + <xsl:variable name="refColumn"><xsl:value-of select="@refColumn"/></xsl:variable>
- + <xsl:if test="$refColumn = 'id'">
- + if ( d-><xsl:value-of select="@name"/>_changed && d-><xsl:value-of select="@name"/> > 0 ) {
- + query.bindValue( QLatin1String(":<xsl:value-of select="@name"/>"), this-><xsl:value-of select="@name"/>() );
- + }
- + </xsl:if>
- + <xsl:if test="$refColumn != 'id'">
- + if ( d-><xsl:value-of select="@name"/>_changed ) {
- + query.bindValue( QLatin1String(":<xsl:value-of select="@name"/>"), this-><xsl:value-of select="@name"/>() );
- + }
- + </xsl:if>
- </xsl:for-each>
- if ( !query.exec() ) {
- @@ -446,10 +472,11 @@
- << query.lastError().text();
- return false;
- }
- -
- + query.next();
- setId( DataStore::self()->lastInsertId( query ) );
- if ( insertId )
- *insertId = id();
- + qDebug() << "############### " << id();
- return true;
- }
- Index: akonadi/server/src/storage/entities.xsl
- ===================================================================
- --- akonadi/server/src/storage/entities.xsl (revision 977078)
- +++ akonadi/server/src/storage/entities.xsl (working copy)
- @@ -163,7 +163,8 @@
- <xsl:value-of select="$className"/> rv(
- <xsl:for-each select="column">
- - query.value( <xsl:value-of select="position() - 1"/> ).value<<xsl:value-of select="@type"/>>()
- + (query.isNull(<xsl:value-of select="position() - 1"/>)) ? <xsl:value-of select="@type"/>() :
- + query.value( <xsl:value-of select="position() - 1"/> ).value<<xsl:value-of select="@type"/>>()
- <xsl:if test="position() != last()">,</xsl:if>
- </xsl:for-each>
- );
- Index: akonadi/server/src/storage/akonadidb.xml
- ===================================================================
- --- akonadi/server/src/storage/akonadidb.xml (revision 977078)
- +++ akonadi/server/src/storage/akonadidb.xml (working copy)
- @@ -72,7 +72,8 @@
- <table name="Resource">
- <column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/>
- - <column name="name" type="QString" sqltype="VARCHAR(255)" properties="BINARY NOT NULL UNIQUE"/>
- + <!-- <column name="name" type="QString" sqltype="VARCHAR(255)" properties="BINARY NOT NULL UNIQUE"/> -->
- + <column name="name" type="QString" sqltype="VARCHAR(255)" properties="NOT NULL UNIQUE"/>
- <reference name="collections" table="Collection" key="resourceId"/>
- <data columns="name" values="'akonadi_search_resource'"/>
- </table>
- @@ -80,9 +81,11 @@
- <table name="Collection">
- <column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/>
- <column name="remoteId" type="QString"/>
- - <column name="name" type="QByteArray" sqltype="VARCHAR(255)" properties="BINARY character set utf8 collate utf8_bin NOT NULL"/>
- - <column name="parentId" type="qint64" refTable="Collection" refColumn="id" methodName="parent" properties="DEFAULT 0 REFERENCES Collection(id)"/>
- - <column name="resourceId" type="qint64" refTable="Resource" refColumn="id" properties="NOT NULL REFERENCES Resource(id)"/>
- + <!-- <column name="name" type="QByteArray" sqltype="VARCHAR(255)" properties="BINARY character set utf8 collate utf8_bin NOT NULL"/>-->
- + <!-- <column name="name" type="QByteArray" sqltype="VARCHAR(255)" properties="character set utf8 collate utf8_bin NOT NULL"/>-->
- + <column name="name" type="QByteArray" sqltype="VARCHAR(255)" properties=" NOT NULL"/>
- + <column name="parentId" type="qint64" refTable="Collection" refColumn="id" methodName="parent" properties="DEFAULT null REFERENCES CollectionTable(id)"/>
- + <column name="resourceId" type="qint64" refTable="Resource" refColumn="id" properties="NOT NULL REFERENCES ResourceTable(id)"/>
- <column name="subscribed" type="bool" default="true" properties="NOT NULL DEFAULT true"/>
- <column name="cachePolicyInherit" type="bool" default="true" properties="NOT NULL DEFAULT true"/>
- <column name="cachePolicyCheckInterval" type="int" default="-1" properties="NOT NULL DEFAULT -1"/>
- @@ -93,7 +96,7 @@
- <reference name="children" table="Collection" key="parentId"/>
- <reference name="items" table="PimItem" key="collectionId"/>
- <reference name="attributes" table="CollectionAttribute" key="collectionId"/>
- - <data columns="parentId,name,resourceId" values="0,'Search',1"/>
- + <data columns="parentId,name,resourceId" values="null,'Search',1"/>
- </table>
- <table name="MimeType">
- @@ -111,8 +114,8 @@
- <column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/>
- <column name="rev" type="int" properties="NOT NULL DEFAULT 0"/>
- <column name="remoteId" type="QString"/>
- - <column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES Collection(id)"/>
- - <column name="mimeTypeId" type="qint64" refTable="MimeType" refColumn="id" properties="REFERENCES MimeType(id)"/>
- + <column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES CollectionTable(id)"/>
- + <column name="mimeTypeId" type="qint64" refTable="MimeType" refColumn="id" properties="REFERENCES MimeTypeTable(id)"/>
- <column name="datetime" type="QDateTime" properties="DEFAULT CURRENT_TIMESTAMP">
- <comment>create/modified time</comment>
- </column>
- @@ -154,7 +157,7 @@
- <table name="CollectionAttribute">
- <column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/>
- - <column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES Collection(id)"/>
- + <column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES CollectionTable(id)"/>
- <column name="type" type="QByteArray" properties="NOT NULL"/>
- <column name="value" type="QByteArray"/>
- <index name="collectionIndex" columns="collectionId" unique="false"/>
- Index: akonadi/server/src/storage/dbconfig.cpp
- ===================================================================
- --- akonadi/server/src/storage/dbconfig.cpp (revision 977078)
- +++ akonadi/server/src/storage/dbconfig.cpp (working copy)
- @@ -38,7 +38,8 @@
- QSettings settings( serverConfigFile, QSettings::IniFormat );
- // determine driver to use
- - const QString defaultDriver = QLatin1String("QMYSQL");
- + // const QString defaultDriver = QLatin1String("QMYSQL");
- + const QString defaultDriver = QLatin1String("QPSQL");
- mDriverName = settings.value( QLatin1String("General/Driver"), defaultDriver ).toString();
- if ( mDriverName.isEmpty() )
- mDriverName = defaultDriver;
- Index: akonadi/server/src/storage/datastore.cpp
- ===================================================================
- --- akonadi/server/src/storage/datastore.cpp (revision 977078)
- +++ akonadi/server/src/storage/datastore.cpp (working copy)
- @@ -48,6 +48,7 @@
- #include <QtSql/QSqlError>
- #include <QtSql/QSqlField>
- #include <QtSql/QSqlQuery>
- +#include <QtSql/QSqlRecord>
- using namespace Akonadi;
- @@ -112,14 +113,14 @@
- bool Akonadi::DataStore::init()
- {
- +
- DbInitializer initializer( m_database, QLatin1String(":akonadidb.xml") );
- if (! initializer.run() ) {
- akError() << initializer.errorMsg();
- return false;
- }
- -
- DbUpdater updater( m_database, QLatin1String( ":dbupdate.xml" ) );
- - if ( !updater.run() )
- + if ( !updater.run())
- return false;
- // enable caching for some tables
- @@ -595,10 +596,16 @@
- //static
- qint64 DataStore::lastInsertId( const QSqlQuery & query )
- {
- - QVariant v = query.lastInsertId();
- - if ( !v.isValid() ) return -1;
- + // QVariant v = query.lastInsertId();
- + // qDebug() << "LAST ID OF " << query.lastError().text() << " " << v.toString();
- + //if ( !v.isValid() ) return -1;
- + qint64 insertId = -1;
- bool ok;
- - qint64 insertId = v.toLongLong( &ok );
- +
- + insertId = query.record().value(QLatin1String("id")).toLongLong(&ok);
- + // insertId = v.toLongLong( &ok );
- +
- + qDebug() << " == " << insertId << ", " << ok;
- if ( !ok ) return -1;
- return insertId;
- }
- Index: akonadi/server/src/storage/dbinitializer.cpp
- ===================================================================
- --- akonadi/server/src/storage/dbinitializer.cpp (revision 977078)
- +++ akonadi/server/src/storage/dbinitializer.cpp (working copy)
- @@ -43,7 +43,7 @@
- bool DbInitializer::run()
- {
- - qDebug() << "DbInitializer::run()";
- + qDebug() << "DbInitializer::run() " << mTemplateFile;
- QFile file( mTemplateFile );
- if ( !file.open( QIODevice::ReadOnly ) ) {
- @@ -168,9 +168,9 @@
- if( element.hasAttribute( QLatin1String("properties") ) )
- columns.append( QLatin1String(", ") + element.attribute( QLatin1String("properties") ) );
- - const QString statement = QString::fromLatin1( "CREATE TABLE %1 (%2);" ).arg( tableName, columns );
- + const QString statement = QString::fromLatin1( "CREATE TABLE %1 (%2);" ).arg( tableName, columns);
- qDebug() << statement;
- -
- +
- if ( !query.exec( statement ) ) {
- mErrorMsg = QLatin1String( "Unable to create entire table.\n" );
- mErrorMsg += QString::fromLatin1( "Query error: '%1'" ).arg( query.lastError().text() );
- @@ -212,7 +212,7 @@
- // TODO: remove obsolete columns (when sqlite will support it) and adapt column type modifications
- }
- -
- +/*
- // add indices
- columnElement = element.firstChildElement();
- while ( !columnElement.isNull() ) {
- @@ -240,8 +240,7 @@
- }
- columnElement = columnElement.nextSiblingElement();
- }
- -
- -
- +*/
- // add initial data if table is empty
- const QString statement = QString::fromLatin1( "SELECT * FROM %1 LIMIT 1" ).arg( tableName );
- if ( !query.exec( statement ) ) {
- @@ -249,7 +248,7 @@
- mErrorMsg += QString::fromLatin1( "Query error: '%1'" ).arg( query.lastError().text() );
- return false;
- }
- - if ( query.size() == 0 || !query.first() ) {
- + if ( query.size() == 0 || !query.first()) {
- foreach ( const QString &stmt, dataList ) {
- if ( !query.exec( stmt ) ) {
- mErrorMsg = QString::fromLatin1( "Unable to add initial data to table '%1'.\n" ).arg( tableName );
- @@ -276,14 +275,14 @@
- if ( !hasTable( tableName ) ) {
- QString statement = QString::fromLatin1( "CREATE TABLE %1 (" ).arg( tableName );
- statement += QString::fromLatin1("%1_%2 INTEGER REFERENCES %3(%4), " )
- - .arg( table1 )
- + .arg( table1)
- .arg( col1 )
- - .arg( table1 )
- + .arg( QString(table1 + QLatin1String("Table")))
- .arg( col1 );
- statement += QString::fromLatin1("%1_%2 INTEGER REFERENCES %3(%4), " )
- - .arg( table2 )
- + .arg( table2)
- .arg( col2 )
- - .arg( table2 )
- + .arg( QString(table2 + QLatin1String("Table")))
- .arg( col2 );
- statement += QString::fromLatin1("PRIMARY KEY (%1_%2, %3_%4));" ).arg( table1 ).arg( col1 ).arg( table2 ).arg( col2 );
- qDebug() << statement;
- @@ -335,7 +334,7 @@
- if ( mDatabase.driverName().startsWith( QLatin1String("QMYSQL") ) ) {
- statement = QString::fromLatin1( "SHOW INDEXES FROM %1" ).arg( tableName );
- statement += QString::fromLatin1( " WHERE `Key_name` = '%1'" ).arg( indexName );
- - } else if( mDatabase.driverName() == QLatin1String("PSQL") ) {
- + } else if( mDatabase.driverName() == QLatin1String("QPSQL") ) {
- statement = QLatin1String( "SELECT indexname FROM pq_indexes" );
- statement += QString::fromLatin1( " WHERE tablename = '%1'" ).arg( tableName );
- statement += QString::fromLatin1( " AND indexname = '%1';" ).arg( indexName );
- Index: akonadi/server/src/handler/create.cpp
- ===================================================================
- --- akonadi/server/src/handler/create.cpp (revision 977078)
- +++ akonadi/server/src/handler/create.cpp (working copy)
- @@ -99,6 +99,7 @@
- Collection collection;
- collection.setParentId( parentId );
- +
- collection.setName( name.toUtf8() );
- collection.setResourceId( resourceId );
- Index: akonadi/server/src/handler/aklist.cpp
- ===================================================================
- --- akonadi/server/src/handler/aklist.cpp (revision 977078)
- +++ akonadi/server/src/handler/aklist.cpp (working copy)
- @@ -141,7 +141,7 @@
- }
- } else {
- if ( depth != 0 ) {
- - Collection::List list = Collection::retrieveFiltered( Collection::parentIdColumn(), 0 );
- + Collection::List list = Collection::retrieveFiltered( Collection::parentIdColumn(), QVariant() );
- collections << list;
- }
- --depth;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement