Advertisement
Guest User

jgoday

a guest
Jun 7th, 2009
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.41 KB | None | 0 0
  1. Akonadi with postgresql, part 2
  2.  
  3. Now, cleaning the last patch, to make more sense, and to limit changes to try to affect the minimum possible to current working mysql support.
  4.  
  5. Here's the new patch.
  6.  
  7. And the list of chages
  8.  
  9. <ul>
  10.    <li>
  11.        <b>Akonadi database description file and schema</b>
  12.        <br/>
  13.        <b>File</b> : kdesupport/akonadi/server/src/storage/akonadidb.xml and kdesupport/akonadi/server/src/storage/akonadidb.xsd
  14.        <br/>
  15.        <b>Changes description</b> :
  16.            * New element 'columnproperty' into column, to describe database type dependent properties
  17.        <br/>
  18.        <div style="border:1px dotted #909090;background-color:#f7f7f7;padding:4px; overflow: auto">
  19.        <code>
  20. Index: akonadi/server/src/storage/akonadidb.xsd
  21. ===================================================================
  22. --- akonadi/server/src/storage/akonadidb.xsd    (revision 978545)
  23. +++ akonadi/server/src/storage/akonadidb.xsd    (working copy)
  24. @@ -67,8 +67,18 @@
  25.     &lt;xsd:attribute name="refColumn"   type="xsd:string"/&gt;
  26.     &lt;xsd:attribute name="methodName"  type="xsd:string"/&gt;
  27.     &lt;xsd:attribute name="properties"  type="xsd:string"/&gt;
  28. +    &lt;xsd:attribute name="dbtype"      type="xsd:string"/&gt;
  29.   &lt;/xsd:complexType&gt;
  30.  
  31. +  &lt;xsd:complexType name="columnpropertyType"&gt;
  32. +    &lt;xsd:attribute name="sqltype"     type="xsd:string" use="required"/&gt;
  33. +    &lt;xsd:attribute name="default"     type="xsd:string"/&gt;
  34. +    &lt;xsd:attribute name="refTable"    type="xsd:string"/&gt;
  35. +    &lt;xsd:attribute name="refColumn"   type="xsd:string"/&gt;
  36. +    &lt;xsd:attribute name="properties"  type="xsd:string" /&gt;
  37. +    &lt;xsd:attribute name="dbtype"      type="xsd:string" use="required"/&gt;
  38. +  &lt;/xsd:complexType&gt;
  39. +
  40.   &lt;xsd:complexType name="indexType"&gt;
  41.     &lt;xsd:attribute name="name"     type="xsd:string"  use="required"/&gt;
  42.     &lt;xsd:attribute name="columns"  type="xsd:string"  use="required"/&gt;
  43. @@ -87,6 +97,7 @@
  44.   &lt;xsd:complexType name="dataType"&gt;
  45.     &lt;xsd:attribute name="columns"  type="xsd:string"  use="required"/&gt;
  46.     &lt;xsd:attribute name="values"   type="xsd:string"  use="required"/&gt;
  47. +    &lt;xsd:attribute name="dbtype"   type="xsd:string"/&gt;
  48.   &lt;/xsd:complexType&gt;
  49.  
  50. &lt;/xsd:schema&gt;
  51. Index: akonadi/server/src/storage/akonadidb.xml
  52. ===================================================================
  53. --- akonadi/server/src/storage/akonadidb.xml    (revision 978545)
  54. +++ akonadi/server/src/storage/akonadidb.xml    (working copy)
  55. @@ -72,7 +72,10 @@
  56.  
  57.   &lt;table name="Resource"&gt;
  58.     &lt;column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/&gt;
  59. -    &lt;column name="name" type="QString" sqltype="VARCHAR(255)" properties="BINARY NOT NULL UNIQUE"/&gt;
  60. +    &lt;column name="name" type="QString"&gt;
  61. +      &lt;columnproperty sqltype="VARCHAR(255)" properties="BINARY NOT NULL UNIQUE" dbtype="QMYSQL"/&gt;
  62. +      &lt;columnproperty sqltype="VARCHAR(255)" properties="NOT NULL UNIQUE" dbtype="QPSQL"/&gt;
  63. +    &lt;/column&gt;
  64.     &lt;reference name="collections" table="Collection" key="resourceId"/&gt;
  65.     &lt;data columns="name" values="'akonadi_search_resource'"/&gt;
  66.   &lt;/table&gt;
  67. @@ -80,9 +83,18 @@
  68.   &lt;table name="Collection"&gt;
  69.     &lt;column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/&gt;
  70.     &lt;column name="remoteId" type="QString"/&gt;
  71. -    &lt;column name="name" type="QByteArray" sqltype="VARCHAR(255)" properties="BINARY character set utf8 collate utf8_bin NOT NULL"/&gt;
  72. -    &lt;column name="parentId" type="qint64" refTable="Collection" refColumn="id" methodName="parent" properties="DEFAULT 0 REFERENCES Collection(id)"/&gt;
  73. -    &lt;column name="resourceId" type="qint64" refTable="Resource" refColumn="id" properties="NOT NULL REFERENCES Resource(id)"/&gt;
  74. +    &lt;column name="name" type="QByteArray"&gt;
  75. +      &lt;columnproperty sqltype="VARCHAR(255)" properties="BINARY character set utf8 collate utf8_bin NOT NULL" dbtype="QMYSQL"/&gt;
  76. +      &lt;columnproperty sqltype="VARCHAR(255)" properties="NOT NULL" dbtype="QPSQL"/&gt;
  77. +    &lt;/column&gt;
  78. +    &lt;column name="parentId" type="qint64" methodName="parent" refTable="Collection" refColumn="id"&gt;
  79. +      &lt;columnproperty sqltype="bigint" properties="DEFAULT 0 REFERENCES Collection(id)" dbtype="QMYSQL"/&gt;
  80. +      &lt;columnproperty sqltype="int8" properties="DEFAULT null REFERENCES CollectionTable(id)" dbtype="QPSQL"/&gt;
  81. +    &lt;/column&gt;
  82. +    &lt;column name="resourceId" type="qint64" refTable="Resource" refColumn="id"&gt;
  83. +      &lt;columnproperty sqltype="bigint" properties="NOT NULL REFERENCES Resource(id)" dbtype="QMYSQL"/&gt;
  84. +      &lt;columnproperty sqltype="int8" properties="NOT NULL REFERENCES ResourceTable(id)" dbtype="QPSQL"/&gt;
  85. +    &lt;/column&gt;
  86.     &lt;column name="subscribed" type="bool" default="true" properties="NOT NULL DEFAULT true"/&gt;
  87.     &lt;column name="cachePolicyInherit" type="bool" default="true" properties="NOT NULL DEFAULT true"/&gt;
  88.     &lt;column name="cachePolicyCheckInterval" type="int" default="-1" properties="NOT NULL DEFAULT -1"/&gt;
  89. @@ -93,7 +105,8 @@
  90.     &lt;reference name="children" table="Collection" key="parentId"/&gt;
  91.     &lt;reference name="items" table="PimItem" key="collectionId"/&gt;
  92.     &lt;reference name="attributes" table="CollectionAttribute" key="collectionId"/&gt;
  93. -    &lt;data columns="parentId,name,resourceId" values="0,'Search',1"/&gt;
  94. +    &lt;data columns="parentId,name,resourceId" values="0,'Search',1" dbtype="QMYSQL"/&gt;
  95. +    &lt;data columns="parentId,name,resourceId" values="null,'Search',1" dbtype="QPSQL"/&gt;
  96.   &lt;/table&gt;
  97.  
  98.   &lt;table name="MimeType"&gt;
  99. @@ -111,8 +124,14 @@
  100.     &lt;column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/&gt;
  101.     &lt;column name="rev" type="int" properties="NOT NULL DEFAULT 0"/&gt;
  102.     &lt;column name="remoteId" type="QString"/&gt;
  103. -    &lt;column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES Collection(id)"/&gt;
  104. -    &lt;column name="mimeTypeId" type="qint64" refTable="MimeType" refColumn="id" properties="REFERENCES MimeType(id)"/&gt;
  105. +    &lt;column name="collectionId" type="qint64" refTable="Collection" refColumn="id"&gt;
  106. +      &lt;columnproperty sqltype="BIGINT" properties="REFERENCES Collection(id)" dbtype="QMYSQL"/&gt;
  107. +      &lt;columnproperty sqltype="int8" properties="REFERENCES CollectionTable(id)" dbtype="QPSQL"/&gt;
  108. +    &lt;/column&gt;
  109. +    &lt;column name="mimeTypeId" type="qint64" refTable="MimeType" refColumn="id"&gt;
  110. +      &lt;columnproperty sqltype="BIGINT" properties="REFERENCES MimeType(id)" dbtype="QMYSQL"/&gt;
  111. +      &lt;columnproperty sqltype="int8" properties="REFERENCES MimeTypeTable(id)" dbtype="QPSQL"/&gt;
  112. +    &lt;/column&gt;
  113.     &lt;column name="datetime" type="QDateTime" properties="DEFAULT CURRENT_TIMESTAMP"&gt;
  114.       &lt;comment&gt;create/modified time&lt;/comment&gt;
  115.     &lt;/column&gt;
  116. @@ -154,7 +173,10 @@
  117.  
  118.   &lt;table name="CollectionAttribute"&gt;
  119.     &lt;column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/&gt;
  120. -    &lt;column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES Collection(id)"/&gt;
  121. +    &lt;column name="collectionId" type="qint64" refTable="Collection" refColumn="id"&gt;
  122. +      &lt;columnproperty sqltype="BIGINT" properties="REFERENCES Collection(id)" dbtype="QMYSQL"/&gt;
  123. +      &lt;columnproperty sqltype="int8" properties="REFERENCES CollectionTable(id)" dbtype="QPSQL"/&gt;
  124. +    &lt;/column&gt;
  125.     &lt;column name="type" type="QByteArray" properties="NOT NULL"/&gt;
  126.     &lt;column name="value" type="QByteArray"/&gt;
  127.     &lt;index name="collectionIndex" columns="collectionId" unique="false"/&gt;
  128.        </code>
  129.        </div>
  130.        <br/>
  131.    </li>
  132.  
  133.    <li>
  134.        <b>Akonadi database storage initializer</b>
  135.        <br/>
  136.        <b>File</b> : kdesupport/akonadi/server/src/storage/dbinitializer.cpp
  137.        <br/>
  138.        <b>Changes description</b> :
  139.            * When postgresql, create database relations with complete table name
  140.            * Check for database type dependent properties
  141.        <br/>
  142.        <div style="border:1px dotted #909090;background-color:#f7f7f7;padding:4px; overflow: auto">
  143.        <code>
  144. --- akonadi/server/src/storage/dbinitializer.cpp    (revision 978545)
  145. +++ akonadi/server/src/storage/dbinitializer.cpp    (working copy)
  146. @@ -132,8 +132,23 @@
  147.         if ( entry.second.startsWith( QLatin1String("CHAR") ) )
  148.           entry.second.replace(QLatin1String("CHAR"), QLatin1String("VARCHAR"));
  149.       }
  150. +      // check the dbtype
  151. +      if ( columnElement.childNodes().size() &gt; 0) {
  152. +        for (int i=0; i&lt;columnElement.childNodes().size(); i++) {
  153. +          QDomElement e = columnElement.childNodes().at(i).toElement();
  154. +
  155. +          if (e.attribute( QLatin1String("dbtype")) == mDatabase.driverName()) {
  156. +            entry.second = e.attribute( QLatin1String("sqltype") );
  157. +            entry.second += QLatin1String(" ") + e.attribute( QLatin1String("properties"));
  158. +          }
  159. +        }
  160. +      }
  161. +
  162.       columnsList.append( entry );
  163. -    } else if ( columnElement.tagName() == QLatin1String( "data" ) ) {
  164. +
  165. +    } else if ( columnElement.tagName() == QLatin1String( "data" ) &amp;&amp;
  166. +        (!columnElement.attributes().contains(QLatin1String ("dbtype")) ||
  167. +          columnElement.attribute( QLatin1String( "dbtype" ) ) == mDatabase.driverName())) {
  168.       QString values = columnElement.attribute( QLatin1String("values") );
  169.       if ( mDatabase.driverName().startsWith( QLatin1String("QMYSQL") ) )
  170.         values.replace( QLatin1String("\\"), QLatin1String("\\\\") );
  171. @@ -168,7 +183,7 @@
  172.     if( element.hasAttribute( QLatin1String("properties") ) )
  173.       columns.append( QLatin1String(", ") + element.attribute( QLatin1String("properties") ) );
  174.  
  175. -    const QString statement = QString::fromLatin1( "CREATE TABLE %1 (%2);" ).arg( tableName, columns );
  176. +    const QString statement = QString::fromLatin1( "CREATE TABLE %1 (%2) WITH OIDS;" ).arg( tableName, columns );
  177.     qDebug() &lt;&lt; statement;
  178.  
  179.     if ( !query.exec( statement ) ) {
  180. @@ -212,7 +227,7 @@
  181.  
  182.     // TODO: remove obsolete columns (when sqlite will support it) and adapt column type modifications
  183.   }
  184. -
  185. +/*
  186.   // add indices
  187.   columnElement = element.firstChildElement();
  188.   while ( !columnElement.isNull() ) {
  189. @@ -240,8 +255,7 @@
  190.     }
  191.     columnElement = columnElement.nextSiblingElement();
  192.   }
  193. -
  194. -
  195. +*/
  196.   // add initial data if table is empty
  197.   const QString statement = QString::fromLatin1( "SELECT * FROM %1 LIMIT 1" ).arg( tableName );
  198.   if ( !query.exec( statement ) ) {
  199. @@ -278,12 +292,12 @@
  200.     statement += QString::fromLatin1("%1_%2 INTEGER REFERENCES %3(%4), " )
  201.         .arg( table1 )
  202.         .arg( col1 )
  203. -        .arg( table1 )
  204. +        .arg( (mDatabase.driverName() == QLatin1String("QPSQL")) ? table1 + QString::fromLatin1("Table") : table1 )
  205.         .arg( col1 );
  206.     statement += QString::fromLatin1("%1_%2 INTEGER REFERENCES %3(%4), " )
  207.         .arg( table2 )
  208.         .arg( col2 )
  209. -        .arg( table2 )
  210. +        .arg( (mDatabase.driverName() == QLatin1String("QPSQL")) ? table2 + QString::fromLatin1("Table") : table2 )
  211.         .arg( col2 );
  212.     statement += QString::fromLatin1("PRIMARY KEY (%1_%2, %3_%4));" ).arg( table1 ).arg( col1 ).arg( table2 ).arg( col2 );
  213.     qDebug() &lt;&lt; statement;
  214. @@ -335,7 +349,7 @@
  215.   if ( mDatabase.driverName().startsWith( QLatin1String("QMYSQL") ) ) {
  216.     statement  = QString::fromLatin1( "SHOW INDEXES FROM %1" ).arg( tableName );
  217.     statement += QString::fromLatin1( " WHERE `Key_name` = '%1'" ).arg( indexName );
  218. -  } else if( mDatabase.driverName() == QLatin1String("PSQL") ) {
  219. +  } else if( mDatabase.driverName() == QLatin1String("QPSQL") ) {
  220.     statement  = QLatin1String( "SELECT indexname FROM pq_indexes" );
  221.     statement += QString::fromLatin1( " WHERE tablename = '%1'" ).arg( tableName );
  222.     statement += QString::fromLatin1( " AND  indexname = '%1';" ).arg( indexName );
  223.        </code>
  224.        </div>
  225.        <br/>
  226.    </li>
  227.  
  228.    <li>
  229.        <b>Collection list handler</b>
  230.        <br/>
  231.        <b>File :</b> kdesupport/akonadi/server/src/handler/aklist.cpp
  232.        <b>Changes description</b> :
  233.            * Get root collections (without parent) with null parent_id instead of 0
  234.        <br/>
  235.        <div style="border:1px dotted #909090;background-color:#f7f7f7;padding:4px; overflow: auto">
  236.        <code>
  237. --- akonadi/server/src/handler/aklist.cpp   (revision 978545)
  238. +++ akonadi/server/src/handler/aklist.cpp   (working copy)
  239. @@ -141,7 +141,7 @@
  240.     }
  241.   } else {
  242.     if ( depth != 0 ) {
  243. -      Collection::List list = Collection::retrieveFiltered( Collection::parentIdColumn(), 0 );
  244. +      Collection::List list = Collection::retrieveFiltered( Collection::parentIdColumn(), QVariant() );
  245.       collections &lt;&lt; list;
  246.     }
  247.     --depth;
  248.        </code>
  249.        </div>
  250.        <br/>
  251.    </li>
  252.  
  253.    <li>
  254.        <b>Entity header</b>
  255.        <br/>
  256.        <b>File :</b> kdesupport/akonadi/server/src/storage/entity.h
  257.        <b>Changes description</b> :
  258.            * Include QSqlRecord header, to manually access recent inserted id when using postgresql
  259.        <br/>
  260.        <div style="border:1px dotted #909090;background-color:#f7f7f7;padding:4px; overflow: auto">
  261.        <code>
  262. --- akonadi/server/src/storage/entity.h (revision 978545)
  263. +++ akonadi/server/src/storage/entity.h (working copy)
  264. @@ -31,6 +31,7 @@
  265. #include &lt;QtSql/QSqlDatabase&gt;
  266. #include &lt;QtSql/QSqlQuery&gt;
  267. #include &lt;QtSql/QSqlError&gt;
  268. +#include &lt;QtSql/QSqlRecord&gt;
  269.        </code>
  270.        </div>
  271.        <br/>
  272.    </li>
  273.  
  274.    <li>
  275.        <b>Entity xsl template</b>
  276.        <br/>
  277.        <b>File :</b> kdesupport/akonadi/server/src/storage/entities.xsl
  278.        <b>Changes description</b> :
  279.            * Check if the value is null before setting it in the entity constructor, to avoid unexpected results (at least with postgresql)
  280.        <br/>
  281.        <div style="border:1px dotted #909090;background-color:#f7f7f7;padding:4px; overflow: auto">
  282.        <code>
  283. --- akonadi/server/src/storage/entities.xsl (revision 978545)
  284. +++ akonadi/server/src/storage/entities.xsl (working copy)
  285. @@ -163,7 +163,8 @@
  286.  
  287.   &lt;xsl:value-of select="$className"/&gt; rv(
  288.   &lt;xsl:for-each select="column"&gt;
  289. -    query.value( &lt;xsl:value-of select="position() - 1"/&gt; ).value&lt;&lt;xsl:value-of select="@type"/&gt;&gt;()
  290. +  (query.isNull(&lt;xsl:value-of select="position() - 1"/&gt;)) ? &lt;xsl:value-of select="@type"/&gt;() :
  291. +                          query.value( &lt;xsl:value-of select="position() - 1"/&gt; ).value&lt;&lt;xsl:value-of select="@type"/&gt;&gt;()
  292.     &lt;xsl:if test="position() != last()"&gt;,&lt;/xsl:if&gt;
  293.   &lt;/xsl:for-each&gt;
  294.   );
  295.        </code>
  296.        </div>
  297.        <br/>
  298.    </li>
  299.  
  300.    <li>
  301.        <b>Entity source (cpp) xsl template</b>
  302.        <br/>
  303.        <b>File :</b> kdesupport/akonadi/server/src/storage/entities-source.xsl
  304.        <b>Changes description</b> :
  305.            <ul>
  306.                <li>extractResult method: check if the value is null before setting it</li>
  307.                <li>retrieveFiltered method: if using postgresql, when filtering by a reference column and null value, use 'is null' instead of ' = 0'</li>
  308.                <li>insert method: - add 'returning id' option when using postgresql to get the inserted id
  309.                             - not insert 0 or null references values
  310.                             - get the inserted id manually when using postgresql ( i cannot make DataStore::lastinsertid work )
  311.                </li>
  312.            </ul>
  313.        <br/>
  314.        <div style="border:1px dotted #909090;background-color:#f7f7f7;padding:4px; overflow: auto">
  315.        <code>
  316. --- akonadi/server/src/storage/entities-source.xsl  (revision 978545)
  317. +++ akonadi/server/src/storage/entities-source.xsl  (working copy)
  318. @@ -237,7 +237,8 @@
  319.   while ( query.next() ) {
  320.     rv.append( &lt;xsl:value-of select="$className"/&gt;(
  321.       &lt;xsl:for-each select="column"&gt;
  322. -        query.value( &lt;xsl:value-of select="position() - 1"/&gt; ).value&lt;&lt;xsl:value-of select="@type"/&gt;&gt;()
  323. +         (query.isNull(&lt;xsl:value-of select="position() - 1"/&gt;)) ? &lt;xsl:value-of select="@type"/&gt;() :
  324. +                          query.value( &lt;xsl:value-of select="position() - 1"/&gt; ).value&lt;&lt;xsl:value-of select="@type"/&gt;&gt;()
  325.         &lt;xsl:if test="position() != last()"&gt;,&lt;/xsl:if&gt;
  326.       &lt;/xsl:for-each&gt;
  327.     ) );
  328. @@ -295,7 +296,10 @@
  329.   statement.append( tableName() );
  330.   statement.append( QLatin1String(" WHERE ") );
  331.   statement.append( key );
  332. -  statement.append( QLatin1String(" = :key") );
  333. +  if ( value.isNull() &amp;&amp; db.driverName() == QLatin1String("QPSQL"))
  334. +    statement.append( QLatin1String(" is null") );
  335. +  else
  336. +    statement.append( QLatin1String(" = :key") );
  337.   query.prepare( statement );
  338.   query.bindValue( QLatin1String(":key"), value );
  339.   if ( !query.exec() ) {
  340. @@ -425,20 +429,42 @@
  341.  
  342.   QStringList cols, vals;
  343.   &lt;xsl:for-each select="column[@name != 'id']"&gt;
  344. -  if ( d-&gt;&lt;xsl:value-of select="@name"/&gt;_changed ) {
  345. -    cols.append( &lt;xsl:value-of select="@name"/&gt;Column() );
  346. -    vals.append( QLatin1String( ":&lt;xsl:value-of select="@name"/&gt;" ) );
  347. -  }
  348. +    &lt;xsl:variable name="refColumn"&gt;&lt;xsl:value-of select="@refColumn"/&gt;&lt;/xsl:variable&gt;
  349. +    &lt;xsl:if test="$refColumn = 'id'"&gt;
  350. +    if ( d-&gt;&lt;xsl:value-of select="@name"/&gt;_changed  &amp;&amp; d-&gt;&lt;xsl:value-of select="@name"/&gt; &gt;  0 ) {
  351. +      cols.append( &lt;xsl:value-of select="@name"/&gt;Column() );
  352. +      vals.append( QLatin1String( ":&lt;xsl:value-of select="@name"/&gt;" ) );
  353. +    }
  354. +    &lt;/xsl:if&gt;
  355. +    &lt;xsl:if test="$refColumn != 'id'"&gt;
  356. +    if ( d-&gt;&lt;xsl:value-of select="@name"/&gt;_changed ) {
  357. +      cols.append( &lt;xsl:value-of select="@name"/&gt;Column() );
  358. +      vals.append( QLatin1String( ":&lt;xsl:value-of select="@name"/&gt;" ) );
  359. +    }
  360. +    &lt;/xsl:if&gt;
  361.   &lt;/xsl:for-each&gt;
  362. -  QString statement = QString::fromLatin1("INSERT INTO &lt;xsl:value-of select="$tableName"/&gt; (%1) VALUES (%2)")
  363. -    .arg( cols.join( QLatin1String(",") ), vals.join( QLatin1String(",") ) );
  364.  
  365. +  QString insertOptions;
  366. +  if (DataStore::self()-&gt;database().driverName() == QLatin1String("QPSQL")) {
  367. +    insertOptions = QLatin1String( " RETURNING id " );
  368. +  }
  369. +  QString statement = QString::fromLatin1("INSERT INTO &lt;xsl:value-of select="$tableName"/&gt; (%1) VALUES (%2) %3")
  370. +    .arg( cols.join( QLatin1String(",") ), vals.join( QLatin1String(",") ), insertOptions );
  371. +
  372.   QSqlQuery query( db );
  373.   query.prepare( statement );
  374.   &lt;xsl:for-each select="column[@name != 'id']"&gt;
  375. -  if ( d-&gt;&lt;xsl:value-of select="@name"/&gt;_changed ) {
  376. -    query.bindValue( QLatin1String(":&lt;xsl:value-of select="@name"/&gt;"), this-&gt;&lt;xsl:value-of select="@name"/&gt;() );
  377. -  }
  378. +    &lt;xsl:variable name="refColumn"&gt;&lt;xsl:value-of select="@refColumn"/&gt;&lt;/xsl:variable&gt;
  379. +    &lt;xsl:if test="$refColumn = 'id'"&gt;
  380. +      if ( d-&gt;&lt;xsl:value-of select="@name"/&gt;_changed &amp;&amp; d-&gt;&lt;xsl:value-of select="@name"/&gt; &gt; 0 ) {
  381. +        query.bindValue( QLatin1String(":&lt;xsl:value-of select="@name"/&gt;"), this-&gt;&lt;xsl:value-of select="@name"/&gt;() );
  382. +      }
  383. +    &lt;/xsl:if&gt;
  384. +    &lt;xsl:if test="$refColumn != 'id'"&gt;
  385. +      if ( d-&gt;&lt;xsl:value-of select="@name"/&gt;_changed ) {
  386. +        query.bindValue( QLatin1String(":&lt;xsl:value-of select="@name"/&gt;"), this-&gt;&lt;xsl:value-of select="@name"/&gt;() );
  387. +      }
  388. +    &lt;/xsl:if&gt;
  389.   &lt;/xsl:for-each&gt;
  390.  
  391.   if ( !query.exec() ) {
  392. @@ -447,7 +473,15 @@
  393.     return false;
  394.   }
  395.  
  396. -  setId( DataStore::self()-&gt;lastInsertId( query ) );
  397. +  // TODO : make postgresql work with DataStore::lastInsertId too
  398. +  if (DataStore::self()-&gt;database().driverName() == QLatin1String("QPSQL")) {
  399. +    query.next();
  400. +    setId( query.record().value(QLatin1String("id")).toLongLong() );
  401. +  }
  402. +  else {
  403. +    setId( DataStore::self()-&gt;lastInsertId( query ) );
  404. +  }
  405. +
  406.   if ( insertId )
  407.     *insertId = id();
  408.   return true;
  409.        </code>
  410.        </div>
  411.        <br/>
  412.    </li>
  413. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement