aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-09-08 10:38:11 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-09-08 10:38:12 (GMT)
commit37817e26d88a777d45dcb624a0766a91e73c8bdf (patch)
tree4ec7b2975514ed02aad0aa944fc21c99f49310e6
parent0d5bcf350ed0a5d0b6248493a24172c0fbfbedb4 (diff)
DBSchema: allow specifying custom identificationColumn for PSQL
Some tables we have don't have the "id" column, so when using PostgreSQL, queries like "INSERT .... RETURNING id" fail. For those table we can now manually specify an identificationColumn or unset it which prevents QueryBuilder from using "RETURNING" in INSERT statements completely. This fixes Tag and Relation support on PostgreSQL.
-rw-r--r--src/server/storage/akonadidb.xml4
-rw-r--r--src/server/storage/akonadidb.xsd1
-rw-r--r--src/server/storage/entities-source.xsl3
-rw-r--r--src/server/storage/entities.xsl1
-rw-r--r--src/server/storage/querybuilder.cpp4
5 files changed, 10 insertions, 3 deletions
diff --git a/src/server/storage/akonadidb.xml b/src/server/storage/akonadidb.xml
index 7d7026a..092e0be 100644
--- a/src/server/storage/akonadidb.xml
+++ b/src/server/storage/akonadidb.xml
@@ -199,7 +199,7 @@
<index name="tagIndex" columns="tagId" unique="false"/>
</table>
- <table name="TagRemoteIdResourceRelation">
+ <table name="TagRemoteIdResourceRelation" identificationColumn="">
<column name="tagId" type="qint64" allowNull="false" refTable="Tag" refColumn="id" onDelete="Cascade" />
<column name="resourceId" type="qint64" allowNull="false" refTable="Resource" refColumn="id" onDelete="Cascade" />
<column name="remoteId" type="QString" allowNull="false" />
@@ -212,7 +212,7 @@
<data columns="id,name" values="1,'GENERIC'"/>
</table>
- <table name="Relation">
+ <table name="Relation" identificationColumn="">
<column name="leftId" type="qint64" allowNull="false" refTable="PimItem" refColumn="id" onDelete="Cascade" methodName="left" />
<column name="rightId" type="qint64" allowNull="false" refTable="PimItem" refColumn="id" onDelete="Cascade" methodName="right" />
<column name="typeId" type="qint64" refTable="RelationType" refColumn="id" onDelete="Restrict" default="1"/>
diff --git a/src/server/storage/akonadidb.xsd b/src/server/storage/akonadidb.xsd
index f447a83..0563a46 100644
--- a/src/server/storage/akonadidb.xsd
+++ b/src/server/storage/akonadidb.xsd
@@ -43,6 +43,7 @@
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="properties" type="xsd:string"/>
+ <xsd:attribute name="identificationColumn" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="relationType">
diff --git a/src/server/storage/entities-source.xsl b/src/server/storage/entities-source.xsl
index 2f28ee2..50a22a4 100644
--- a/src/server/storage/entities-source.xsl
+++ b/src/server/storage/entities-source.xsl
@@ -583,6 +583,9 @@ bool <xsl:value-of select="$className"/>::insert( qint64* insertId )
return false;
QueryBuilder qb( tableName(), QueryBuilder::Insert );
+ <xsl:if test="@identificationColumn">
+ qb.setIdentificationColumn(QLatin1String("<xsl:value-of select="@identificationColumn"/>"));
+ </xsl:if>
<xsl:for-each select="column[@name != 'id']">
<xsl:variable name="refColumn"><xsl:value-of select="@refColumn"/></xsl:variable>
<xsl:if test="$refColumn = 'id'">
diff --git a/src/server/storage/entities.xsl b/src/server/storage/entities.xsl
index 3bfcc54..6fb1e92 100644
--- a/src/server/storage/entities.xsl
+++ b/src/server/storage/entities.xsl
@@ -103,6 +103,7 @@ Q_DECLARE_TYPEINFO( Akonadi::Server::<xsl:value-of select="@name"/>, Q_MOVABLE_T
#include &lt;qvariant.h&gt;
#include &lt;QtCore/QHash&gt;
#include &lt;QtCore/QMutex&gt;
+#include &lt;QtCore/QThread&gt;
using namespace Akonadi;
using namespace Akonadi::Server;
diff --git a/src/server/storage/querybuilder.cpp b/src/server/storage/querybuilder.cpp
index 5fa968b..10a6da8 100644
--- a/src/server/storage/querybuilder.cpp
+++ b/src/server/storage/querybuilder.cpp
@@ -591,8 +591,10 @@ void QueryBuilder::setIdentificationColumn(const QString &column)
qint64 QueryBuilder::insertId()
{
if (mDatabaseType == DbType::PostgreSQL) {
- Q_ASSERT(!mIdentificationColumn.isEmpty());
query().next();
+ if (mIdentificationColumn.isEmpty()) {
+ return 0; // FIXME: Does this make sense?
+ }
return query().record().value(mIdentificationColumn).toLongLong();
} else {
const QVariant v = query().lastInsertId();