Advertisement
Guest User

jgoday

a guest
Jun 6th, 2009
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.53 KB | None | 0 0
  1. Index: akonadi/server/src/storage/entities-source.xsl
  2. ===================================================================
  3. --- akonadi/server/src/storage/entities-source.xsl  (revision 977078)
  4. +++ akonadi/server/src/storage/entities-source.xsl  (working copy)
  5. @@ -237,7 +237,8 @@
  6.    while ( query.next() ) {
  7.      rv.append( <xsl:value-of select="$className"/>(
  8.        <xsl:for-each select="column">
  9. -        query.value( <xsl:value-of select="position() - 1"/> ).value&lt;<xsl:value-of select="@type"/>&gt;()
  10. +         (query.isNull(<xsl:value-of select="position() - 1"/>)) ? <xsl:value-of select="@type"/>() :
  11. +                          query.value( <xsl:value-of select="position() - 1"/> ).value&lt;<xsl:value-of select="@type"/>&gt;()
  12.          <xsl:if test="position() != last()">,</xsl:if>
  13.        </xsl:for-each>
  14.      ) );
  15. @@ -249,6 +250,7 @@
  16.  <xsl:if test="column[@name='id']">
  17.  <xsl:value-of select="$className"/><xsl:text> </xsl:text><xsl:value-of select="$className"/>::retrieveById( qint64 id )
  18.  {
  19. +  qDebug() &lt;&lt; " :: RETRIEVE BY ID :: " &lt;&lt; id;
  20.    <xsl:call-template name="data-retrieval">
  21.    <xsl:with-param name="key">id</xsl:with-param>
  22.    <xsl:with-param name="cache">idCache</xsl:with-param>
  23. @@ -268,6 +270,8 @@
  24.  
  25.  QList&lt;<xsl:value-of select="$className"/>&gt; <xsl:value-of select="$className"/>::retrieveAll()
  26.  {
  27. +  qDebug() &lt;&lt; "::: Retrieve ALL ";
  28. +
  29.    QSqlDatabase db = DataStore::self()->database();
  30.    if ( !db.isOpen() )
  31.      return QList&lt;<xsl:value-of select="$className"/>&gt;();
  32. @@ -286,6 +290,7 @@
  33.  
  34.  QList&lt;<xsl:value-of select="$className"/>&gt; <xsl:value-of select="$className"/>::retrieveFiltered( const QString &amp;key, const QVariant &amp;value )
  35.  {
  36. +  qDebug() &lt;&lt; "::::: RETRIEVE FILTERED " &lt;&lt; key;
  37.    QSqlDatabase db = DataStore::self()->database();
  38.    if ( !db.isOpen() )
  39.      return QList&lt;<xsl:value-of select="$className"/>&gt;();
  40. @@ -295,7 +300,10 @@
  41.    statement.append( tableName() );
  42.    statement.append( QLatin1String(" WHERE ") );
  43.    statement.append( key );
  44. -  statement.append( QLatin1String(" = :key") );
  45. +  if ( value.isNull() )
  46. +    statement.append( QLatin1String(" is null") );
  47. +  else
  48. +    statement.append( QLatin1String(" = :key") );
  49.    query.prepare( statement );
  50.    query.bindValue( QLatin1String(":key"), value );
  51.    if ( !query.exec() ) {
  52. @@ -425,20 +433,38 @@
  53.  
  54.    QStringList cols, vals;
  55.    <xsl:for-each select="column[@name != 'id']">
  56. -  if ( d-&gt;<xsl:value-of select="@name"/>_changed ) {
  57. -    cols.append( <xsl:value-of select="@name"/>Column() );
  58. -    vals.append( QLatin1String( ":<xsl:value-of select="@name"/>" ) );
  59. -  }
  60. +    <xsl:variable name="refColumn"><xsl:value-of select="@refColumn"/></xsl:variable>
  61. +    <xsl:if test="$refColumn = 'id'">
  62. +    if ( d-&gt;<xsl:value-of select="@name"/>_changed  &amp;&amp; d-&gt;<xsl:value-of select="@name"/> &gt;  0 ) {
  63. +      cols.append( <xsl:value-of select="@name"/>Column() );
  64. +      vals.append( QLatin1String( ":<xsl:value-of select="@name"/>" ) );
  65. +    }
  66. +    </xsl:if>
  67. +    <xsl:if test="$refColumn != 'id'">
  68. +    if ( d-&gt;<xsl:value-of select="@name"/>_changed ) {
  69. +      cols.append( <xsl:value-of select="@name"/>Column() );
  70. +      vals.append( QLatin1String( ":<xsl:value-of select="@name"/>" ) );
  71. +    }
  72. +    </xsl:if>
  73.    </xsl:for-each>
  74. -  QString statement = QString::fromLatin1("INSERT INTO <xsl:value-of select="$tableName"/> (%1) VALUES (%2)")
  75. -    .arg( cols.join( QLatin1String(",") ), vals.join( QLatin1String(",") ) );
  76.  
  77. +  QString statement = QString::fromLatin1("INSERT INTO <xsl:value-of select="$tableName"/> (%1) VALUES (%2) %3")
  78. +    .arg( cols.join( QLatin1String(",") ), vals.join( QLatin1String(",") ), QLatin1String(" RETURNING id") );
  79. +
  80.    QSqlQuery query( db );
  81.    query.prepare( statement );
  82.    <xsl:for-each select="column[@name != 'id']">
  83. -  if ( d-&gt;<xsl:value-of select="@name"/>_changed ) {
  84. -    query.bindValue( QLatin1String(":<xsl:value-of select="@name"/>"), this-&gt;<xsl:value-of select="@name"/>() );
  85. -  }
  86. +    <xsl:variable name="refColumn"><xsl:value-of select="@refColumn"/></xsl:variable>
  87. +    <xsl:if test="$refColumn = 'id'">
  88. +      if ( d-&gt;<xsl:value-of select="@name"/>_changed &amp;&amp; d-&gt;<xsl:value-of select="@name"/> &gt; 0 ) {
  89. +        query.bindValue( QLatin1String(":<xsl:value-of select="@name"/>"), this-&gt;<xsl:value-of select="@name"/>() );
  90. +      }
  91. +    </xsl:if>
  92. +    <xsl:if test="$refColumn != 'id'">
  93. +      if ( d-&gt;<xsl:value-of select="@name"/>_changed ) {
  94. +        query.bindValue( QLatin1String(":<xsl:value-of select="@name"/>"), this-&gt;<xsl:value-of select="@name"/>() );
  95. +      }
  96. +    </xsl:if>
  97.    </xsl:for-each>
  98.  
  99.    if ( !query.exec() ) {
  100. @@ -446,10 +472,11 @@
  101.        &lt;&lt; query.lastError().text();
  102.      return false;
  103.    }
  104. -
  105. +  query.next();
  106.    setId( DataStore::self()->lastInsertId( query ) );
  107.    if ( insertId )
  108.      *insertId = id();
  109. +  qDebug() &lt;&lt; "############### " &lt;&lt; id();
  110.    return true;
  111.  }
  112.  
  113. Index: akonadi/server/src/storage/entities.xsl
  114. ===================================================================
  115. --- akonadi/server/src/storage/entities.xsl (revision 977078)
  116. +++ akonadi/server/src/storage/entities.xsl (working copy)
  117. @@ -163,7 +163,8 @@
  118.  
  119.    <xsl:value-of select="$className"/> rv(
  120.    <xsl:for-each select="column">
  121. -    query.value( <xsl:value-of select="position() - 1"/> ).value&lt;<xsl:value-of select="@type"/>&gt;()
  122. +  (query.isNull(<xsl:value-of select="position() - 1"/>)) ? <xsl:value-of select="@type"/>() :
  123. +                          query.value( <xsl:value-of select="position() - 1"/> ).value&lt;<xsl:value-of select="@type"/>&gt;()
  124.      <xsl:if test="position() != last()">,</xsl:if>
  125.    </xsl:for-each>
  126.    );
  127. Index: akonadi/server/src/storage/akonadidb.xml
  128. ===================================================================
  129. --- akonadi/server/src/storage/akonadidb.xml    (revision 977078)
  130. +++ akonadi/server/src/storage/akonadidb.xml    (working copy)
  131. @@ -72,7 +72,8 @@
  132.  
  133.    <table name="Resource">
  134.      <column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/>
  135. -    <column name="name" type="QString" sqltype="VARCHAR(255)" properties="BINARY NOT NULL UNIQUE"/>
  136. +    <!-- <column name="name" type="QString" sqltype="VARCHAR(255)" properties="BINARY NOT NULL UNIQUE"/> -->
  137. +    <column name="name" type="QString" sqltype="VARCHAR(255)" properties="NOT NULL UNIQUE"/>
  138.      <reference name="collections" table="Collection" key="resourceId"/>
  139.      <data columns="name" values="'akonadi_search_resource'"/>
  140.    </table>
  141. @@ -80,9 +81,11 @@
  142.    <table name="Collection">
  143.      <column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/>
  144.      <column name="remoteId" type="QString"/>
  145. -    <column name="name" type="QByteArray" sqltype="VARCHAR(255)" properties="BINARY character set utf8 collate utf8_bin NOT NULL"/>
  146. -    <column name="parentId" type="qint64" refTable="Collection" refColumn="id" methodName="parent" properties="DEFAULT 0 REFERENCES Collection(id)"/>
  147. -    <column name="resourceId" type="qint64" refTable="Resource" refColumn="id" properties="NOT NULL REFERENCES Resource(id)"/>
  148. +    <!-- <column name="name" type="QByteArray" sqltype="VARCHAR(255)" properties="BINARY character set utf8 collate utf8_bin NOT NULL"/>-->
  149. +    <!-- <column name="name" type="QByteArray" sqltype="VARCHAR(255)" properties="character set utf8 collate utf8_bin NOT NULL"/>-->
  150. +    <column name="name" type="QByteArray" sqltype="VARCHAR(255)" properties=" NOT NULL"/>
  151. +    <column name="parentId" type="qint64" refTable="Collection" refColumn="id" methodName="parent" properties="DEFAULT null REFERENCES CollectionTable(id)"/>
  152. +    <column name="resourceId" type="qint64" refTable="Resource" refColumn="id" properties="NOT NULL REFERENCES ResourceTable(id)"/>
  153.      <column name="subscribed" type="bool" default="true" properties="NOT NULL DEFAULT true"/>
  154.      <column name="cachePolicyInherit" type="bool" default="true" properties="NOT NULL DEFAULT true"/>
  155.      <column name="cachePolicyCheckInterval" type="int" default="-1" properties="NOT NULL DEFAULT -1"/>
  156. @@ -93,7 +96,7 @@
  157.      <reference name="children" table="Collection" key="parentId"/>
  158.      <reference name="items" table="PimItem" key="collectionId"/>
  159.      <reference name="attributes" table="CollectionAttribute" key="collectionId"/>
  160. -    <data columns="parentId,name,resourceId" values="0,'Search',1"/>
  161. +    <data columns="parentId,name,resourceId" values="null,'Search',1"/>
  162.    </table>
  163.  
  164.    <table name="MimeType">
  165. @@ -111,8 +114,8 @@
  166.      <column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/>
  167.      <column name="rev" type="int" properties="NOT NULL DEFAULT 0"/>
  168.      <column name="remoteId" type="QString"/>
  169. -    <column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES Collection(id)"/>
  170. -    <column name="mimeTypeId" type="qint64" refTable="MimeType" refColumn="id" properties="REFERENCES MimeType(id)"/>
  171. +    <column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES CollectionTable(id)"/>
  172. +    <column name="mimeTypeId" type="qint64" refTable="MimeType" refColumn="id" properties="REFERENCES MimeTypeTable(id)"/>
  173.      <column name="datetime" type="QDateTime" properties="DEFAULT CURRENT_TIMESTAMP">
  174.        <comment>create/modified time</comment>
  175.      </column>
  176. @@ -154,7 +157,7 @@
  177.  
  178.    <table name="CollectionAttribute">
  179.      <column name="id" type="qint64" properties="NOT NULL PRIMARY KEY AUTOINCREMENT"/>
  180. -    <column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES Collection(id)"/>
  181. +    <column name="collectionId" type="qint64" refTable="Collection" refColumn="id" properties="REFERENCES CollectionTable(id)"/>
  182.      <column name="type" type="QByteArray" properties="NOT NULL"/>
  183.      <column name="value" type="QByteArray"/>
  184.      <index name="collectionIndex" columns="collectionId" unique="false"/>
  185. Index: akonadi/server/src/storage/dbconfig.cpp
  186. ===================================================================
  187. --- akonadi/server/src/storage/dbconfig.cpp (revision 977078)
  188. +++ akonadi/server/src/storage/dbconfig.cpp (working copy)
  189. @@ -38,7 +38,8 @@
  190.        QSettings settings( serverConfigFile, QSettings::IniFormat );
  191.  
  192.        // determine driver to use
  193. -      const QString defaultDriver = QLatin1String("QMYSQL");
  194. +      // const QString defaultDriver = QLatin1String("QMYSQL");
  195. +      const QString defaultDriver = QLatin1String("QPSQL");
  196.        mDriverName = settings.value( QLatin1String("General/Driver"), defaultDriver ).toString();
  197.        if ( mDriverName.isEmpty() )
  198.          mDriverName = defaultDriver;
  199. Index: akonadi/server/src/storage/datastore.cpp
  200. ===================================================================
  201. --- akonadi/server/src/storage/datastore.cpp    (revision 977078)
  202. +++ akonadi/server/src/storage/datastore.cpp    (working copy)
  203. @@ -48,6 +48,7 @@
  204.  #include <QtSql/QSqlError>
  205.  #include <QtSql/QSqlField>
  206.  #include <QtSql/QSqlQuery>
  207. +#include <QtSql/QSqlRecord>
  208.  
  209.  using namespace Akonadi;
  210.  
  211. @@ -112,14 +113,14 @@
  212.  
  213.  bool Akonadi::DataStore::init()
  214.  {
  215. +
  216.    DbInitializer initializer( m_database, QLatin1String(":akonadidb.xml") );
  217.    if (! initializer.run() ) {
  218.      akError() << initializer.errorMsg();
  219.      return false;
  220.    }
  221. -
  222.    DbUpdater updater( m_database, QLatin1String( ":dbupdate.xml" ) );
  223. -  if ( !updater.run() )
  224. +  if ( !updater.run())
  225.      return false;
  226.  
  227.    // enable caching for some tables
  228. @@ -595,10 +596,16 @@
  229.  //static
  230.  qint64 DataStore::lastInsertId( const QSqlQuery & query )
  231.  {
  232. -    QVariant v = query.lastInsertId();
  233. -    if ( !v.isValid() ) return -1;
  234. + //   QVariant v = query.lastInsertId();
  235. +   // qDebug() << "LAST ID OF " << query.lastError().text() << " " << v.toString();
  236. +    //if ( !v.isValid() ) return -1;
  237. +    qint64 insertId = -1;
  238.      bool ok;
  239. -    qint64 insertId = v.toLongLong( &ok );
  240. +
  241. +      insertId = query.record().value(QLatin1String("id")).toLongLong(&ok);
  242. +       // insertId = v.toLongLong( &ok );
  243. +
  244. +    qDebug() << " == " << insertId << ", " << ok;
  245.      if ( !ok ) return -1;
  246.      return insertId;
  247.  }
  248. Index: akonadi/server/src/storage/dbinitializer.cpp
  249. ===================================================================
  250. --- akonadi/server/src/storage/dbinitializer.cpp    (revision 977078)
  251. +++ akonadi/server/src/storage/dbinitializer.cpp    (working copy)
  252. @@ -43,7 +43,7 @@
  253.  
  254.  bool DbInitializer::run()
  255.  {
  256. -  qDebug() << "DbInitializer::run()";
  257. +  qDebug() << "DbInitializer::run() " << mTemplateFile;
  258.  
  259.    QFile file( mTemplateFile );
  260.    if ( !file.open( QIODevice::ReadOnly ) ) {
  261. @@ -168,9 +168,9 @@
  262.      if( element.hasAttribute( QLatin1String("properties") ) )
  263.        columns.append( QLatin1String(", ") + element.attribute( QLatin1String("properties") ) );
  264.  
  265. -    const QString statement = QString::fromLatin1( "CREATE TABLE %1 (%2);" ).arg( tableName, columns );
  266. +    const QString statement = QString::fromLatin1( "CREATE TABLE %1 (%2);" ).arg( tableName, columns);
  267.      qDebug() << statement;
  268. -
  269. +    
  270.      if ( !query.exec( statement ) ) {
  271.        mErrorMsg = QLatin1String( "Unable to create entire table.\n" );
  272.        mErrorMsg += QString::fromLatin1( "Query error: '%1'" ).arg( query.lastError().text() );
  273. @@ -212,7 +212,7 @@
  274.  
  275.      // TODO: remove obsolete columns (when sqlite will support it) and adapt column type modifications
  276.    }
  277. -
  278. +/*
  279.    // add indices
  280.    columnElement = element.firstChildElement();
  281.    while ( !columnElement.isNull() ) {
  282. @@ -240,8 +240,7 @@
  283.      }
  284.      columnElement = columnElement.nextSiblingElement();
  285.    }
  286. -
  287. -
  288. +*/
  289.    // add initial data if table is empty
  290.    const QString statement = QString::fromLatin1( "SELECT * FROM %1 LIMIT 1" ).arg( tableName );
  291.    if ( !query.exec( statement ) ) {
  292. @@ -249,7 +248,7 @@
  293.      mErrorMsg += QString::fromLatin1( "Query error: '%1'" ).arg( query.lastError().text() );
  294.      return false;
  295.    }
  296. -  if ( query.size() == 0  || !query.first() ) {
  297. +  if ( query.size() == 0 || !query.first()) {
  298.      foreach ( const QString &stmt, dataList ) {
  299.        if ( !query.exec( stmt ) ) {
  300.          mErrorMsg = QString::fromLatin1( "Unable to add initial data to table '%1'.\n" ).arg( tableName );
  301. @@ -276,14 +275,14 @@
  302.    if ( !hasTable( tableName ) ) {
  303.      QString statement = QString::fromLatin1( "CREATE TABLE %1 (" ).arg( tableName );
  304.      statement += QString::fromLatin1("%1_%2 INTEGER REFERENCES %3(%4), " )
  305. -        .arg( table1 )
  306. +        .arg( table1)
  307.          .arg( col1 )
  308. -        .arg( table1 )
  309. +        .arg( QString(table1 + QLatin1String("Table")))
  310.          .arg( col1 );
  311.      statement += QString::fromLatin1("%1_%2 INTEGER REFERENCES %3(%4), " )
  312. -        .arg( table2 )
  313. +        .arg( table2)
  314.          .arg( col2 )
  315. -        .arg( table2 )
  316. +        .arg( QString(table2 + QLatin1String("Table")))
  317.          .arg( col2 );
  318.      statement += QString::fromLatin1("PRIMARY KEY (%1_%2, %3_%4));" ).arg( table1 ).arg( col1 ).arg( table2 ).arg( col2 );
  319.      qDebug() << statement;
  320. @@ -335,7 +334,7 @@
  321.    if ( mDatabase.driverName().startsWith( QLatin1String("QMYSQL") ) ) {
  322.      statement  = QString::fromLatin1( "SHOW INDEXES FROM %1" ).arg( tableName );
  323.      statement += QString::fromLatin1( " WHERE `Key_name` = '%1'" ).arg( indexName );
  324. -  } else if( mDatabase.driverName() == QLatin1String("PSQL") ) {
  325. +  } else if( mDatabase.driverName() == QLatin1String("QPSQL") ) {
  326.      statement  = QLatin1String( "SELECT indexname FROM pq_indexes" );
  327.      statement += QString::fromLatin1( " WHERE tablename = '%1'" ).arg( tableName );
  328.      statement += QString::fromLatin1( " AND  indexname = '%1';" ).arg( indexName );
  329. Index: akonadi/server/src/handler/create.cpp
  330. ===================================================================
  331. --- akonadi/server/src/handler/create.cpp   (revision 977078)
  332. +++ akonadi/server/src/handler/create.cpp   (working copy)
  333. @@ -99,6 +99,7 @@
  334.  
  335.    Collection collection;
  336.    collection.setParentId( parentId );
  337. +
  338.    collection.setName( name.toUtf8() );
  339.    collection.setResourceId( resourceId );
  340.  
  341. Index: akonadi/server/src/handler/aklist.cpp
  342. ===================================================================
  343. --- akonadi/server/src/handler/aklist.cpp   (revision 977078)
  344. +++ akonadi/server/src/handler/aklist.cpp   (working copy)
  345. @@ -141,7 +141,7 @@
  346.      }
  347.    } else {
  348.      if ( depth != 0 ) {
  349. -      Collection::List list = Collection::retrieveFiltered( Collection::parentIdColumn(), 0 );
  350. +      Collection::List list = Collection::retrieveFiltered( Collection::parentIdColumn(), QVariant() );
  351.        collections << list;
  352.      }
  353.      --depth;
  354.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement