A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FSqlite</id>
		<title>C++/Qt/Sqlite - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FSqlite"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/Sqlite&amp;action=history"/>
		<updated>2026-04-18T18:32:39Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/Sqlite&amp;diff=994&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/Sqlite&amp;diff=994&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/Sqlite&amp;diff=995&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/Sqlite&amp;diff=995&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:28Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Connect to Sqlite and do insert, delete, update and select==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
Foundations of Qt Development\Chapter13\sqltest\sqlite\main.cpp&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QtSql&amp;gt;&lt;br /&gt;
#include &amp;lt;QtDebug&amp;gt;&lt;br /&gt;
int main( int argc, char **argv )&lt;br /&gt;
{&lt;br /&gt;
  QApplication app( argc, argv );&lt;br /&gt;
  QSqlDatabase db = QSqlDatabase::addDatabase( &amp;quot;QSQLITE&amp;quot; );&lt;br /&gt;
  db.setDatabaseName( &amp;quot;./testdatabase.db&amp;quot; );&lt;br /&gt;
  if( !db.open() )&lt;br /&gt;
  {&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; db.lastError();&lt;br /&gt;
    qFatal( &amp;quot;Failed to connect.&amp;quot; );&lt;br /&gt;
  }&lt;br /&gt;
    &lt;br /&gt;
  qDebug( &amp;quot;Connected!&amp;quot; );&lt;br /&gt;
  &lt;br /&gt;
  QSqlQuery qry;&lt;br /&gt;
  qry.prepare( &amp;quot;CREATE TABLE IF NOT EXISTS names (id INTEGER UNIQUE PRIMARY KEY, firstname VARCHAR(30), lastname VARCHAR(30))&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; &amp;quot;Table created!&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
  qry.prepare( &amp;quot;INSERT INTO names (id, firstname, lastname) VALUES (1, &amp;quot;John&amp;quot;, &amp;quot;Doe&amp;quot;)&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Inserted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;INSERT INTO names (id, firstname, lastname) VALUES (2, &amp;quot;Jane&amp;quot;, &amp;quot;Doe&amp;quot;)&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Inserted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;INSERT INTO names (id, firstname, lastname) VALUES (3, &amp;quot;James&amp;quot;, &amp;quot;Doe&amp;quot;)&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Inserted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;INSERT INTO names (id, firstname, lastname) VALUES (4, &amp;quot;Judy&amp;quot;, &amp;quot;Doe&amp;quot;)&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Inserted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;INSERT INTO names (id, firstname, lastname) VALUES (5, &amp;quot;Richard&amp;quot;, &amp;quot;Roe&amp;quot;)&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Inserted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;INSERT INTO names (id, firstname, lastname) VALUES (6, &amp;quot;Jane&amp;quot;, &amp;quot;Roe&amp;quot;)&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Inserted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;INSERT INTO names (id, firstname, lastname) VALUES (7, &amp;quot;John&amp;quot;, &amp;quot;Noakes&amp;quot;)&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Inserted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;INSERT INTO names (id, firstname, lastname) VALUES (8, &amp;quot;Donna&amp;quot;, &amp;quot;Doe&amp;quot;)&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Inserted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;INSERT INTO names (id, firstname, lastname) VALUES (9, &amp;quot;Ralph&amp;quot;, &amp;quot;Roe&amp;quot;)&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Inserted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;SELECT * FROM names&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
  {&lt;br /&gt;
    qDebug( &amp;quot;Selected!&amp;quot; );&lt;br /&gt;
    &lt;br /&gt;
    QSqlRecord rec = qry.record();&lt;br /&gt;
    &lt;br /&gt;
    int cols = rec.count();&lt;br /&gt;
    &lt;br /&gt;
    for( int c=0; c&amp;lt;cols; c++ )&lt;br /&gt;
      qDebug() &amp;lt;&amp;lt; QString( &amp;quot;Column %1: %2&amp;quot; ).arg( c ).arg( rec.fieldName(c) );&lt;br /&gt;
      &lt;br /&gt;
    for( int r=0; qry.next(); r++ )&lt;br /&gt;
      for( int c=0; c&amp;lt;cols; c++ )&lt;br /&gt;
        qDebug() &amp;lt;&amp;lt; QString( &amp;quot;Row %1, %2: %3&amp;quot; ).arg( r ).arg( rec.fieldName(c) ).arg( qry.value(c).toString() );&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  qry.prepare( &amp;quot;SELECT firstname, lastname FROM names WHERE lastname = &amp;quot;Roe&amp;quot;&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
  {&lt;br /&gt;
    qDebug( &amp;quot;Selected!&amp;quot; );&lt;br /&gt;
    &lt;br /&gt;
    QSqlRecord rec = qry.record();&lt;br /&gt;
    &lt;br /&gt;
    int cols = rec.count();&lt;br /&gt;
    &lt;br /&gt;
    for( int c=0; c&amp;lt;cols; c++ )&lt;br /&gt;
      qDebug() &amp;lt;&amp;lt; QString( &amp;quot;Column %1: %2&amp;quot; ).arg( c ).arg( rec.fieldName(c) );&lt;br /&gt;
      &lt;br /&gt;
    for( int r=0; qry.next(); r++ )&lt;br /&gt;
      for( int c=0; c&amp;lt;cols; c++ )&lt;br /&gt;
        qDebug() &amp;lt;&amp;lt; QString( &amp;quot;Row %1, %2: %3&amp;quot; ).arg( r ).arg( rec.fieldName(c) ).arg( qry.value(c).toString() );&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  qry.prepare( &amp;quot;SELECT firstname, lastname FROM names WHERE lastname = &amp;quot;Roe&amp;quot; ORDER BY firstname&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
  {&lt;br /&gt;
    qDebug( &amp;quot;Selected!&amp;quot; );&lt;br /&gt;
    &lt;br /&gt;
    QSqlRecord rec = qry.record();&lt;br /&gt;
    &lt;br /&gt;
    int cols = rec.count();&lt;br /&gt;
    &lt;br /&gt;
    for( int c=0; c&amp;lt;cols; c++ )&lt;br /&gt;
      qDebug() &amp;lt;&amp;lt; QString( &amp;quot;Column %1: %2&amp;quot; ).arg( c ).arg( rec.fieldName(c) );&lt;br /&gt;
      &lt;br /&gt;
    for( int r=0; qry.next(); r++ )&lt;br /&gt;
      for( int c=0; c&amp;lt;cols; c++ )&lt;br /&gt;
        qDebug() &amp;lt;&amp;lt; QString( &amp;quot;Row %1, %2: %3&amp;quot; ).arg( r ).arg( rec.fieldName(c) ).arg( qry.value(c).toString() );&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  qry.prepare( &amp;quot;SELECT lastname, COUNT(*) as &amp;quot;members&amp;quot; FROM names GROUP BY lastname ORDER BY lastname&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
  {&lt;br /&gt;
    qDebug( &amp;quot;Selected!&amp;quot; );&lt;br /&gt;
    &lt;br /&gt;
    QSqlRecord rec = qry.record();&lt;br /&gt;
    &lt;br /&gt;
    int cols = rec.count();&lt;br /&gt;
    &lt;br /&gt;
    for( int c=0; c&amp;lt;cols; c++ )&lt;br /&gt;
      qDebug() &amp;lt;&amp;lt; QString( &amp;quot;Column %1: %2&amp;quot; ).arg( c ).arg( rec.fieldName(c) );&lt;br /&gt;
      &lt;br /&gt;
    for( int r=0; qry.next(); r++ )&lt;br /&gt;
      for( int c=0; c&amp;lt;cols; c++ )&lt;br /&gt;
        qDebug() &amp;lt;&amp;lt; QString( &amp;quot;Row %1, %2: %3&amp;quot; ).arg( r ).arg( rec.fieldName(c) ).arg( qry.value(c).toString() );&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  qry.prepare( &amp;quot;UPDATE names SET firstname = &amp;quot;Nisse&amp;quot;, lastname = &amp;quot;Svensson&amp;quot; WHERE id = 7&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Updated!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;UPDATE names SET lastname = &amp;quot;Johnson&amp;quot; WHERE firstname = &amp;quot;Jane&amp;quot;&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Updated!&amp;quot; );&lt;br /&gt;
  &lt;br /&gt;
  qry.prepare( &amp;quot;DELETE FROM names WHERE id = 7&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Deleted!&amp;quot; );&lt;br /&gt;
  qry.prepare( &amp;quot;DELETE FROM names WHERE lastname = &amp;quot;Johnson&amp;quot;&amp;quot; );&lt;br /&gt;
  if( !qry.exec() )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; qry.lastError();&lt;br /&gt;
  else&lt;br /&gt;
    qDebug( &amp;quot;Deleted!&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
  db.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>