can initialize the KnownSourcesCache, and import the old sources.
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 27 Jun 2006 16:19:00 +0000 (16:19 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 27 Jun 2006 16:19:00 +0000 (16:19 +0000)
next steps: implement knownSources, port SourceManager

13 files changed:
configure.ac
devel/devel.dmacvicar/testbed.cc
zypp/Makefile.am
zypp/cache/KnownSourcesCache.cpp [new file with mode: 0644]
zypp/cache/KnownSourcesCache.h [new file with mode: 0644]
zypp/cache/Makefile.am [new file with mode: 0644]
zypp/cache/sqlite3x/Makefile.am [new file with mode: 0644]
zypp/cache/sqlite3x/sqlite3x.hpp [new file with mode: 0644]
zypp/cache/sqlite3x/sqlite3x_command.cpp [new file with mode: 0644]
zypp/cache/sqlite3x/sqlite3x_connection.cpp [new file with mode: 0644]
zypp/cache/sqlite3x/sqlite3x_exception.cpp [new file with mode: 0644]
zypp/cache/sqlite3x/sqlite3x_reader.cpp [new file with mode: 0644]
zypp/cache/sqlite3x/sqlite3x_transaction.cpp [new file with mode: 0644]

index 1519c9a8e189ff3a525d94b07b7d58c761d99712..be7ecb2cfa13fc4ebfeabfed53030837116334cc 100644 (file)
@@ -250,7 +250,9 @@ AC_OUTPUT(   po/Makefile.in\
        zypp/pool/Makefile              \
        zypp/solver/Makefile            \
        zypp/solver/detail/Makefile     \
-       zypp/source/Makefile            \
+       zypp/cache/Makefile \
+  zypp/cache/sqlite3x/Makefile
+  zypp/source/Makefile         \
        zypp/source/plaindir/Makefile   \
        zypp/source/susetags/Makefile   \
        zypp/source/yum/Makefile        \
index 0a8a880ca366f3fd01d885309c3a28852f20aeb6..4ff4862d18b3e8f338601ef7375f7a12affb7e65 100644 (file)
 #include <zypp/TranslatedText.h>
 ///////////////////////////////////////////////////////////////////
 
-#include <zypp/parser/yum/YUMParser.h>
 #include <zypp/base/Logger.h>
-#include <zypp/NVRAD.h>
-#include <zypp/target/rpm/RpmDb.h>
-#include <zypp/source/yum/YUMScriptImpl.h>
-#include <zypp/source/yum/YUMMessageImpl.h>
-#include <zypp/source/yum/YUMPackageImpl.h>
-#include <zypp/source/yum/YUMSourceImpl.h>
+
 
 #include <map>
 #include <set>
 
-#include <zypp/CapFactory.h>
-#include <zypp/KeyRing.h>
-#include <zypp/PublicKey.h>
+#include "zypp/CapFactory.h"
+#include "zypp/KeyRing.h"
+#include "zypp/PublicKey.h"
+
+#include "zypp/cache/KnownSourcesCache.h"
 
 using namespace zypp::detail;
 
 using namespace std;
 using namespace zypp;
-using namespace zypp::parser::yum;
-using namespace zypp::source::yum;
-
-
 
 //using namespace DbXml;
 
 int main()
 {
-  zypp::devel::PublicKey k("/suse/dmacvicar/duncan.txt");
-  
-  cout << k.id() << std::endl;
-  cout << k.fingerprint() << std::endl;
-  cout << k.name() << std::endl;
-  
+  cache::KnownSourcesCache("/");
 }
 
 
index 8167dd0e3b592cb5270273d10f79b3b8c96c995b..22b895063da742f1d7f3ec4110358707370ebb73 100644 (file)
@@ -2,7 +2,7 @@
 ## ##################################################
 
 SUBDIRS = base thread url media capability detail pool parser \
-       source target solver zypp_detail ui
+       source cache target solver zypp_detail ui
 
 AM_CXXFLAGS = -DZYPP_BASE_LOGGER_LOGGROUP=\"zypp\"
 
@@ -173,6 +173,7 @@ lib@PACKAGE@_la_LIBADD =        thread/lib@PACKAGE@_thread.la               \
                                pool/lib@PACKAGE@_pool.la               \
                                parser/lib@PACKAGE@_parser.la           \
                                source/lib@PACKAGE@_source.la           \
+                               cache/lib@PACKAGE@_cache.la             \
                                media/lib@PACKAGE@_media.la             \
                                url/lib@PACKAGE@_url.la                 \
                                target/lib@PACKAGE@_target.la           \
diff --git a/zypp/cache/KnownSourcesCache.cpp b/zypp/cache/KnownSourcesCache.cpp
new file mode 100644 (file)
index 0000000..bf0c88a
--- /dev/null
@@ -0,0 +1,110 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#include "zypp/base/Logger.h"
+#include "zypp/cache/KnownSourcesCache.h"
+#include "zypp/target/store/PersistentStorage.h"
+#include "zypp/cache/sqlite3x/sqlite3x.hpp"
+
+#define ZYPP_DB_FILE "/var/lib/zypp/zypp.db"
+
+using namespace sqlite3x;
+using namespace std;
+
+//////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+namespace cache
+{ /////////////////////////////////////////////////////////////////
+
+KnownSourcesCache::KnownSourcesCache( const Pathname &root_r )
+{
+  try
+  {
+    sqlite3_connection con(ZYPP_DB_FILE);
+    
+    {
+      int count = con.executeint("select count(*) from sqlite_master where type='table' and name='sources';");
+      if( count==0 )
+      {
+        con.executenonquery("create table sources (  id integer primary key autoincrement,  alias varchar,  url varchar,  description varchar,  enabled integer, autorefresh integer, type varchar, cachedir varchar, path varchar);");
+        
+        try
+        {
+          // import old sources
+          storage::PersistentStorage store;
+          store.init( root_r );
+          source::SourceInfoList old_sources = store.storedSources();
+          for ( source::SourceInfoList::const_iterator it = old_sources.begin(); it != old_sources.end(); it++ )
+          {
+            storeSource( *it );
+          }
+        }
+        catch(std::exception &e)
+        {
+          ERR << "Exception Occured: " << e.what() << endl;
+        } 
+      }
+    }
+    
+    con.close();
+  }
+  catch(exception &ex) {
+    ERR << "Exception Occured: " << ex.what() << endl;
+  } 
+}
+
+KnownSourcesCache::~KnownSourcesCache()
+{
+}
+
+source::SourceInfoList KnownSourcesCache::knownSources() const
+{
+  return source::SourceInfoList();
+}
+
+void KnownSourcesCache::storeSource( const source::SourceInfo &info )
+{
+  try
+  {
+    sqlite3_connection con(ZYPP_DB_FILE);
+    sqlite3_transaction trans(con);
+
+    {
+      sqlite3_command cmd(con, "insert into sources ( alias, url, description, enabled, autorefresh, type, cachedir, path) values ( ?, ?, ?, ? , ?, ?, ?, ?);");
+      cmd.bind(1, info.alias());
+      cmd.bind(2, info.url().asCompleteString());
+      // FIXME 
+      cmd.bind(4, info.enabled() ? 1 : 0 );
+      cmd.bind(5, info.autorefresh() ? 1 : 0 );
+      cmd.bind(6, info.type());
+      cmd.bind(6, info.cacheDir().asString());
+      cmd.bind(7, info.path().asString());
+      
+      cmd.executenonquery();
+    }
+
+    trans.commit(); // note: if trans goes out of scope (due to an exception or anything else) before calling commit(), it will automatically rollback()
+
+    con.close();
+  }
+  catch(exception &ex) {
+    ERR << "Exception Occured: " << ex.what() << endl;
+  }
+} 
+
+std::ostream & KnownSourcesCache::dumpOn( std::ostream & str ) const
+{
+  return str;
+}
+
+}
+}
+
diff --git a/zypp/cache/KnownSourcesCache.h b/zypp/cache/KnownSourcesCache.h
new file mode 100644 (file)
index 0000000..567d6d8
--- /dev/null
@@ -0,0 +1,66 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/KnownSourcesCache.h
+ *
+*/
+#ifndef ZYPP_KnownSourcesCache_H
+#define ZYPP_KnownSourcesCache_H
+
+#include <iosfwd>
+#include <string>
+
+#include "zypp/base/ReferenceCounted.h"
+#include "zypp/base/NonCopyable.h"
+#include "zypp/base/PtrTypes.h"
+#include "zypp/source/SourceInfo.h"
+#include "zypp/Pathname.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace cache
+  { /////////////////////////////////////////////////////////////////
+
+    DEFINE_PTR_TYPE(KnownSourcesCache);
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // CLASS NAME : KnownSourcesCache
+    //
+    class KnownSourcesCache : public base::ReferenceCounted, private base::NonCopyable
+    {
+      friend std::ostream & operator<<( std::ostream & str, const KnownSourcesCache & obj );
+
+    public:
+      /** root path */
+      KnownSourcesCache( const Pathname &root_r );
+      ~KnownSourcesCache();
+      source::SourceInfoList knownSources() const;
+      void storeSource( const source::SourceInfo &info );    
+    protected:
+
+      /** Overload to realize stream output. */
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      //typedef std::map<media::MediaNr, media::MediaAccessId> MediaMap
+    };
+    ///////////////////////////////////////////////////////////////////
+
+    /** \relates KnownSourcesCache Stream output */
+    inline std::ostream & operator<<( std::ostream & str, const KnownSourcesCache & obj )
+    { return obj.dumpOn( str ); }
+
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace cache
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SOURCE_KnownSourcesCache_H
diff --git a/zypp/cache/Makefile.am b/zypp/cache/Makefile.am
new file mode 100644 (file)
index 0000000..6627338
--- /dev/null
@@ -0,0 +1,25 @@
+SUBDIRS = sqlite3x
+
+INCLUDES = -DZYPP_BASE_LOGGER_LOGGROUP=\"cache\"
+
+## ##################################################
+
+cacheincludedir = $(pkgincludedir)/cache
+
+cacheinclude_HEADERS = KnownSourcesCache.h
+
+## ##################################################
+
+noinst_LTLIBRARIES =   lib@PACKAGE@_cache.la
+
+## ##################################################
+
+lib@PACKAGE@_cache_la_SOURCES =        KnownSourcesCache.cpp
+
+lib@PACKAGE@_cache_la_LDFLAGS = @LIBZYPP_VERSION_INFO@
+
+lib@PACKAGE@_cache_la_LIBADD = sqlite3x/lib@PACKAGE@_sqlite3x.la
+##     hal/lib@PACKAGE@_cache_hal.la \
+##     modalias/lib@PACKAGE@_cache_modalias.la \
+##     store/lib@PACKAGE@_cache_store.la
+
diff --git a/zypp/cache/sqlite3x/Makefile.am b/zypp/cache/sqlite3x/Makefile.am
new file mode 100644 (file)
index 0000000..5543f97
--- /dev/null
@@ -0,0 +1,20 @@
+SUBDIRS =
+
+INCLUDES = -DZYPP_BASE_LOGGER_LOGGROUP=\"sqlite3x\"
+
+## ##################################################
+
+sqlite3xincludedir = $(pkgincludedir)/sqlite3x
+
+sqlite3xinclude_HEADERS = sqlite3x.hpp
+
+## ##################################################
+
+noinst_LTLIBRARIES =   lib@PACKAGE@_sqlite3x.la
+
+## ##################################################
+
+lib@PACKAGE@_sqlite3x_la_SOURCES =     sqlite3x_command.cpp sqlite3x_connection.cpp \
+       sqlite3x_exception.cpp sqlite3x_reader.cpp sqlite3x_transaction.cpp
+       
+lib@PACKAGE@_sqlite3x_la_LDFLAGS = -lsqlite3 @LIBZYPP_VERSION_INFO@
diff --git a/zypp/cache/sqlite3x/sqlite3x.hpp b/zypp/cache/sqlite3x/sqlite3x.hpp
new file mode 100644 (file)
index 0000000..d0e517e
--- /dev/null
@@ -0,0 +1,183 @@
+/*\r
+       Copyright (C) 2004-2005 Cory Nelson\r
+\r
+       This software is provided 'as-is', without any express or implied\r
+       warranty.  In no event will the authors be held liable for any damages\r
+       arising from the use of this software.\r
+\r
+       Permission is granted to anyone to use this software for any purpose,\r
+       including commercial applications, and to alter it and redistribute it\r
+       freely, subject to the following restrictions:\r
+\r
+       1. The origin of this software must not be misrepresented; you must not\r
+               claim that you wrote the original software. If you use this software\r
+               in a product, an acknowledgment in the product documentation would be\r
+               appreciated but is not required.\r
+       2. Altered source versions must be plainly marked as such, and must not be\r
+               misrepresented as being the original software.\r
+       3. This notice may not be removed or altered from any source distribution.\r
+       \r
+       CVS Info :\r
+               $Author: phrostbyte $\r
+               $Date: 2005/06/16 20:46:40 $\r
+               $Revision: 1.1 $\r
+*/\r
+\r
+#ifndef __SQLITE3X_HPP__\r
+#define __SQLITE3X_HPP__\r
+\r
+#include <string>\r
+#include <exception>\r
+#include <stdexcept>\r
+#include <boost/utility.hpp>\r
+\r
+namespace sqlite3x\r
+{\r
+       class sqlite3_connection : boost::noncopyable\r
+        {\r
+       private:\r
+               friend class sqlite3_command;\r
+               friend class database_error;\r
+\r
+               struct sqlite3 *db;\r
+\r
+       public:\r
+               sqlite3_connection();\r
+               sqlite3_connection(const char *db);\r
+               sqlite3_connection(const wchar_t *db);\r
+               ~sqlite3_connection();\r
+\r
+               void open(const char *db);\r
+               void open(const wchar_t *db);\r
+               void close();\r
+\r
+               long long insertid();\r
+               void setbusytimeout(int ms);\r
+\r
+               void executenonquery(const char *sql);\r
+               void executenonquery(const wchar_t *sql);\r
+               void executenonquery(const std::string &sql);\r
+               void executenonquery(const std::wstring &sql);\r
+\r
+               int executeint(const char *sql);\r
+               int executeint(const wchar_t *sql);\r
+               int executeint(const std::string &sql);\r
+               int executeint(const std::wstring &sql);\r
+\r
+               long long executeint64(const char *sql);\r
+               long long executeint64(const wchar_t *sql);\r
+               long long executeint64(const std::string &sql);\r
+               long long executeint64(const std::wstring &sql);\r
+\r
+               double executedouble(const char *sql);\r
+               double executedouble(const wchar_t *sql);\r
+               double executedouble(const std::string &sql);\r
+               double executedouble(const std::wstring &sql);\r
+\r
+               std::string executestring(const char *sql);\r
+               std::string executestring(const wchar_t *sql);\r
+               std::string executestring(const std::string &sql);\r
+               std::string executestring(const std::wstring &sql);\r
+\r
+               std::wstring executestring16(const char *sql);\r
+               std::wstring executestring16(const wchar_t *sql);\r
+               std::wstring executestring16(const std::string &sql);\r
+               std::wstring executestring16(const std::wstring &sql);\r
+\r
+               std::string executeblob(const char *sql);\r
+               std::string executeblob(const wchar_t *sql);\r
+               std::string executeblob(const std::string &sql);\r
+               std::string executeblob(const std::wstring &sql);\r
+       };\r
+\r
+        class sqlite3_command;\r
+\r
+        class database_error : public std::runtime_error {\r
+          public:\r
+            database_error(const char *msg);\r
+            database_error(sqlite3_connection &con);\r
+        };\r
+        \r
+       class sqlite3_transaction : boost::noncopyable {\r
+       private:\r
+               sqlite3_connection &con;\r
+               bool intrans;\r
+\r
+       public:\r
+               sqlite3_transaction(sqlite3_connection &con, bool start=true);\r
+               ~sqlite3_transaction();\r
+\r
+               void begin();\r
+               void commit();\r
+               void rollback();\r
+       };\r
+\r
+        class sqlite3_reader {\r
+          private:\r
+            friend class sqlite3_command;\r
+\r
+            sqlite3_command *cmd;\r
+\r
+            sqlite3_reader(sqlite3_command *cmd);\r
+\r
+          public:\r
+            sqlite3_reader();\r
+            sqlite3_reader(const sqlite3_reader &copy);\r
+            ~sqlite3_reader();\r
+\r
+            sqlite3_reader& operator=(const sqlite3_reader &copy);\r
+\r
+            bool read();\r
+            void reset();\r
+            void close();\r
+\r
+            int getint(int index);\r
+            long long getint64(int index);\r
+            double getdouble(int index);\r
+            std::string getstring(int index);\r
+            std::wstring getstring16(int index);\r
+            std::string getblob(int index);\r
+\r
+            std::string getcolname(int index);\r
+            std::wstring getcolname16(int index);\r
+        };\r
+        \r
+        class sqlite3_command : boost::noncopyable {\r
+          private:\r
+            friend class sqlite3_reader;\r
+\r
+            sqlite3_connection &con;\r
+            struct sqlite3_stmt *stmt;\r
+            unsigned int refs;\r
+            int argc;\r
+\r
+          public:\r
+            sqlite3_command(sqlite3_connection &con, const char *sql);\r
+            sqlite3_command(sqlite3_connection &con, const wchar_t *sql);\r
+            sqlite3_command(sqlite3_connection &con, const std::string &sql);\r
+            sqlite3_command(sqlite3_connection &con, const std::wstring &sql);\r
+            ~sqlite3_command();\r
+\r
+            void bind(int index);\r
+            void bind(int index, int data);\r
+            void bind(int index, long long data);\r
+            void bind(int index, double data);\r
+            void bind(int index, const char *data, int datalen);\r
+            void bind(int index, const wchar_t *data, int datalen);\r
+            void bind(int index, const void *data, int datalen);\r
+            void bind(int index, const std::string &data);\r
+            void bind(int index, const std::wstring &data);\r
+\r
+            sqlite3_reader executereader();\r
+            void executenonquery();\r
+            int executeint();\r
+            long long executeint64();\r
+            double executedouble();\r
+            std::string executestring();\r
+            std::wstring executestring16();\r
+            std::string executeblob();\r
+        };\r
+        \r
+}\r
+\r
+#endif\r
diff --git a/zypp/cache/sqlite3x/sqlite3x_command.cpp b/zypp/cache/sqlite3x/sqlite3x_command.cpp
new file mode 100644 (file)
index 0000000..2d3748d
--- /dev/null
@@ -0,0 +1,156 @@
+/*\r
+       Copyright (C) 2004-2005 Cory Nelson\r
+\r
+       This software is provided 'as-is', without any express or implied\r
+       warranty.  In no event will the authors be held liable for any damages\r
+       arising from the use of this software.\r
+\r
+       Permission is granted to anyone to use this software for any purpose,\r
+       including commercial applications, and to alter it and redistribute it\r
+       freely, subject to the following restrictions:\r
+\r
+       1. The origin of this software must not be misrepresented; you must not\r
+               claim that you wrote the original software. If you use this software\r
+               in a product, an acknowledgment in the product documentation would be\r
+               appreciated but is not required.\r
+       2. Altered source versions must be plainly marked as such, and must not be\r
+               misrepresented as being the original software.\r
+       3. This notice may not be removed or altered from any source distribution.\r
+       \r
+       CVS Info :\r
+               $Author: phrostbyte $\r
+               $Date: 2005/06/16 20:46:40 $\r
+               $Revision: 1.1 $\r
+*/\r
+\r
+#include <sqlite3.h>\r
+#include "sqlite3x.hpp"\r
+\r
+namespace sqlite3x {\r
+\r
+sqlite3_command::sqlite3_command(sqlite3_connection &con, const char *sql) : con(con),refs(0) {\r
+       const char *tail=NULL;\r
+       if(sqlite3_prepare(con.db, sql, -1, &this->stmt, &tail)!=SQLITE_OK)\r
+               throw database_error(con);\r
+\r
+       this->argc=sqlite3_column_count(this->stmt);\r
+}\r
+\r
+sqlite3_command::sqlite3_command(sqlite3_connection &con, const wchar_t *sql) : con(con),refs(0) {\r
+       const wchar_t *tail=NULL;\r
+       if(sqlite3_prepare16(con.db, sql, -1, &this->stmt, (const void**)&tail)!=SQLITE_OK)\r
+               throw database_error(con);\r
+\r
+       this->argc=sqlite3_column_count(this->stmt);\r
+}\r
+\r
+sqlite3_command::sqlite3_command(sqlite3_connection &con, const std::string &sql) : con(con),refs(0) {\r
+       const char *tail=NULL;\r
+       if(sqlite3_prepare(con.db, sql.data(), (int)sql.length(), &this->stmt, &tail)!=SQLITE_OK)\r
+               throw database_error(con);\r
+\r
+       this->argc=sqlite3_column_count(this->stmt);\r
+}\r
+\r
+sqlite3_command::sqlite3_command(sqlite3_connection &con, const std::wstring &sql) : con(con),refs(0) {\r
+       const wchar_t *tail=NULL;\r
+       if(sqlite3_prepare16(con.db, sql.data(), (int)sql.length()*2, &this->stmt, (const void**)&tail)!=SQLITE_OK)\r
+               throw database_error(con);\r
+\r
+       this->argc=sqlite3_column_count(this->stmt);\r
+}\r
+\r
+sqlite3_command::~sqlite3_command() {\r
+       sqlite3_finalize(this->stmt);\r
+}\r
+\r
+void sqlite3_command::bind(int index) {\r
+       if(sqlite3_bind_null(this->stmt, index)!=SQLITE_OK)\r
+               throw database_error(this->con);\r
+}\r
+\r
+void sqlite3_command::bind(int index, int data) {\r
+       if(sqlite3_bind_int(this->stmt, index, data)!=SQLITE_OK)\r
+               throw database_error(this->con);\r
+}\r
+\r
+void sqlite3_command::bind(int index, long long data) {\r
+       if(sqlite3_bind_int64(this->stmt, index, data)!=SQLITE_OK)\r
+               throw database_error(this->con);\r
+}\r
+\r
+void sqlite3_command::bind(int index, double data) {\r
+       if(sqlite3_bind_double(this->stmt, index, data)!=SQLITE_OK)\r
+               throw database_error(this->con);\r
+}\r
+\r
+void sqlite3_command::bind(int index, const char *data, int datalen) {\r
+       if(sqlite3_bind_text(this->stmt, index, data, datalen, SQLITE_TRANSIENT)!=SQLITE_OK)\r
+               throw database_error(this->con);\r
+}\r
+\r
+void sqlite3_command::bind(int index, const wchar_t *data, int datalen) {\r
+       if(sqlite3_bind_text16(this->stmt, index, data, datalen, SQLITE_TRANSIENT)!=SQLITE_OK)\r
+               throw database_error(this->con);\r
+}\r
+\r
+void sqlite3_command::bind(int index, const void *data, int datalen) {\r
+       if(sqlite3_bind_blob(this->stmt, index, data, datalen, SQLITE_TRANSIENT)!=SQLITE_OK)\r
+               throw database_error(this->con);\r
+}\r
+\r
+void sqlite3_command::bind(int index, const std::string &data) {\r
+       if(sqlite3_bind_text(this->stmt, index, data.data(), (int)data.length(), SQLITE_TRANSIENT)!=SQLITE_OK)\r
+               throw database_error(this->con);\r
+}\r
+\r
+void sqlite3_command::bind(int index, const std::wstring &data) {\r
+       if(sqlite3_bind_text16(this->stmt, index, data.data(), (int)data.length()*2, SQLITE_TRANSIENT)!=SQLITE_OK)\r
+               throw database_error(this->con);\r
+}\r
+\r
+sqlite3_reader sqlite3_command::executereader() {\r
+       return sqlite3_reader(this);\r
+}\r
+\r
+void sqlite3_command::executenonquery() {\r
+       this->executereader().read();\r
+}\r
+\r
+int sqlite3_command::executeint() {\r
+       sqlite3_reader reader=this->executereader();\r
+       if(!reader.read()) throw database_error("nothing to read");\r
+       return reader.getint(0);\r
+}\r
+\r
+long long sqlite3_command::executeint64() {\r
+       sqlite3_reader reader=this->executereader();\r
+       if(!reader.read()) throw database_error("nothing to read");\r
+       return reader.getint64(0);\r
+}\r
+\r
+double sqlite3_command::executedouble() {\r
+       sqlite3_reader reader=this->executereader();\r
+       if(!reader.read()) throw database_error("nothing to read");\r
+       return reader.getdouble(0);\r
+}\r
+\r
+std::string sqlite3_command::executestring() {\r
+       sqlite3_reader reader=this->executereader();\r
+       if(!reader.read()) throw database_error("nothing to read");\r
+       return reader.getstring(0);\r
+}\r
+\r
+std::wstring sqlite3_command::executestring16() {\r
+       sqlite3_reader reader=this->executereader();\r
+       if(!reader.read()) throw database_error("nothing to read");\r
+       return reader.getstring16(0);\r
+}\r
+\r
+std::string sqlite3_command::executeblob() {\r
+       sqlite3_reader reader=this->executereader();\r
+       if(!reader.read()) throw database_error("nothing to read");\r
+       return reader.getblob(0);\r
+}\r
+\r
+}\r
diff --git a/zypp/cache/sqlite3x/sqlite3x_connection.cpp b/zypp/cache/sqlite3x/sqlite3x_connection.cpp
new file mode 100644 (file)
index 0000000..9143387
--- /dev/null
@@ -0,0 +1,209 @@
+/*\r
+       Copyright (C) 2004-2005 Cory Nelson\r
+\r
+       This software is provided 'as-is', without any express or implied\r
+       warranty.  In no event will the authors be held liable for any damages\r
+       arising from the use of this software.\r
+\r
+       Permission is granted to anyone to use this software for any purpose,\r
+       including commercial applications, and to alter it and redistribute it\r
+       freely, subject to the following restrictions:\r
+\r
+       1. The origin of this software must not be misrepresented; you must not\r
+               claim that you wrote the original software. If you use this software\r
+               in a product, an acknowledgment in the product documentation would be\r
+               appreciated but is not required.\r
+       2. Altered source versions must be plainly marked as such, and must not be\r
+               misrepresented as being the original software.\r
+       3. This notice may not be removed or altered from any source distribution.\r
+       \r
+       CVS Info :\r
+               $Author: phrostbyte $\r
+               $Date: 2005/06/16 20:46:40 $\r
+               $Revision: 1.1 $\r
+*/\r
+\r
+#include <sqlite3.h>\r
+#include "sqlite3x.hpp"\r
+\r
+namespace sqlite3x {\r
+\r
+sqlite3_connection::sqlite3_connection() : db(NULL) {}\r
+\r
+sqlite3_connection::sqlite3_connection(const char *db) : db(NULL) { this->open(db); }\r
+\r
+sqlite3_connection::sqlite3_connection(const wchar_t *db) : db(NULL) { this->open(db); }\r
+\r
+sqlite3_connection::~sqlite3_connection() { if(this->db) sqlite3_close(this->db); }\r
+\r
+void sqlite3_connection::open(const char *db) {\r
+       if(sqlite3_open(db, &this->db)!=SQLITE_OK)\r
+               throw database_error("unable to open database");\r
+}\r
+\r
+void sqlite3_connection::open(const wchar_t *db) {\r
+       if(sqlite3_open16(db, &this->db)!=SQLITE_OK)\r
+               throw database_error("unable to open database");\r
+}\r
+\r
+void sqlite3_connection::close() {\r
+       if(this->db) {\r
+               if(sqlite3_close(this->db)!=SQLITE_OK)\r
+                       throw database_error(*this);\r
+               this->db=NULL;\r
+       }\r
+}\r
+\r
+long long sqlite3_connection::insertid() {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_last_insert_rowid(this->db);\r
+}\r
+\r
+void sqlite3_connection::setbusytimeout(int ms) {\r
+       if(!this->db) throw database_error("database is not open");\r
+\r
+       if(sqlite3_busy_timeout(this->db, ms)!=SQLITE_OK)\r
+               throw database_error(*this);\r
+}\r
+\r
+void sqlite3_connection::executenonquery(const char *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       sqlite3_command(*this, sql).executenonquery();\r
+}\r
+\r
+void sqlite3_connection::executenonquery(const wchar_t *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       sqlite3_command(*this, sql).executenonquery();\r
+}\r
+\r
+void sqlite3_connection::executenonquery(const std::string &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       sqlite3_command(*this, sql).executenonquery();\r
+}\r
+\r
+void sqlite3_connection::executenonquery(const std::wstring &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       sqlite3_command(*this, sql).executenonquery();\r
+}\r
+\r
+int sqlite3_connection::executeint(const char *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeint();\r
+}\r
+\r
+int sqlite3_connection::executeint(const wchar_t *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeint();\r
+}\r
+\r
+int sqlite3_connection::executeint(const std::string &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeint();\r
+}\r
+\r
+int sqlite3_connection::executeint(const std::wstring &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeint();\r
+}\r
+\r
+long long sqlite3_connection::executeint64(const char *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeint64();\r
+}\r
+\r
+long long sqlite3_connection::executeint64(const wchar_t *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeint64();\r
+}\r
+\r
+long long sqlite3_connection::executeint64(const std::string &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeint64();\r
+}\r
+\r
+long long sqlite3_connection::executeint64(const std::wstring &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeint64();\r
+}\r
+\r
+double sqlite3_connection::executedouble(const char *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executedouble();\r
+}\r
+\r
+double sqlite3_connection::executedouble(const wchar_t *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executedouble();\r
+}\r
+\r
+double sqlite3_connection::executedouble(const std::string &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executedouble();\r
+}\r
+\r
+double sqlite3_connection::executedouble(const std::wstring &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executedouble();\r
+}\r
+\r
+std::string sqlite3_connection::executestring(const char *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executestring();\r
+}\r
+\r
+std::string sqlite3_connection::executestring(const wchar_t *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executestring();\r
+}\r
+\r
+std::string sqlite3_connection::executestring(const std::string &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executestring();\r
+}\r
+\r
+std::string sqlite3_connection::executestring(const std::wstring &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executestring();\r
+}\r
+\r
+std::wstring sqlite3_connection::executestring16(const char *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executestring16();\r
+}\r
+\r
+std::wstring sqlite3_connection::executestring16(const wchar_t *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executestring16();\r
+}\r
+\r
+std::wstring sqlite3_connection::executestring16(const std::string &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executestring16();\r
+}\r
+\r
+std::wstring sqlite3_connection::executestring16(const std::wstring &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executestring16();\r
+}\r
+\r
+std::string sqlite3_connection::executeblob(const char *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeblob();\r
+}\r
+\r
+std::string sqlite3_connection::executeblob(const wchar_t *sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeblob();\r
+}\r
+\r
+std::string sqlite3_connection::executeblob(const std::string &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeblob();\r
+}\r
+\r
+std::string sqlite3_connection::executeblob(const std::wstring &sql) {\r
+       if(!this->db) throw database_error("database is not open");\r
+       return sqlite3_command(*this, sql).executeblob();\r
+}\r
+\r
+}\r
diff --git a/zypp/cache/sqlite3x/sqlite3x_exception.cpp b/zypp/cache/sqlite3x/sqlite3x_exception.cpp
new file mode 100644 (file)
index 0000000..d56f4aa
--- /dev/null
@@ -0,0 +1,34 @@
+/*\r
+       Copyright (C) 2004-2005 Cory Nelson\r
+\r
+       This software is provided 'as-is', without any express or implied\r
+       warranty.  In no event will the authors be held liable for any damages\r
+       arising from the use of this software.\r
+\r
+       Permission is granted to anyone to use this software for any purpose,\r
+       including commercial applications, and to alter it and redistribute it\r
+       freely, subject to the following restrictions:\r
+\r
+       1. The origin of this software must not be misrepresented; you must not\r
+               claim that you wrote the original software. If you use this software\r
+               in a product, an acknowledgment in the product documentation would be\r
+               appreciated but is not required.\r
+       2. Altered source versions must be plainly marked as such, and must not be\r
+               misrepresented as being the original software.\r
+       3. This notice may not be removed or altered from any source distribution.\r
+       \r
+       CVS Info :\r
+               $Author: phrostbyte $\r
+               $Date: 2005/06/16 20:46:40 $\r
+               $Revision: 1.1 $\r
+*/\r
+\r
+#include <sqlite3.h>\r
+#include "sqlite3x.hpp"\r
+\r
+namespace sqlite3x {\r
+\r
+database_error::database_error(const char *msg) : runtime_error(msg) {}\r
+database_error::database_error(sqlite3_connection &con) : runtime_error(sqlite3_errmsg(con.db)) {}\r
+\r
+}\r
diff --git a/zypp/cache/sqlite3x/sqlite3x_reader.cpp b/zypp/cache/sqlite3x/sqlite3x_reader.cpp
new file mode 100644 (file)
index 0000000..2b3d5f3
--- /dev/null
@@ -0,0 +1,129 @@
+/*\r
+       Copyright (C) 2004-2005 Cory Nelson\r
+\r
+       This software is provided 'as-is', without any express or implied\r
+       warranty.  In no event will the authors be held liable for any damages\r
+       arising from the use of this software.\r
+\r
+       Permission is granted to anyone to use this software for any purpose,\r
+       including commercial applications, and to alter it and redistribute it\r
+       freely, subject to the following restrictions:\r
+\r
+       1. The origin of this software must not be misrepresented; you must not\r
+               claim that you wrote the original software. If you use this software\r
+               in a product, an acknowledgment in the product documentation would be\r
+               appreciated but is not required.\r
+       2. Altered source versions must be plainly marked as such, and must not be\r
+               misrepresented as being the original software.\r
+       3. This notice may not be removed or altered from any source distribution.\r
+       \r
+       CVS Info :\r
+               $Author: phrostbyte $\r
+               $Date: 2005/06/16 20:46:40 $\r
+               $Revision: 1.1 $\r
+*/\r
+\r
+#include <sqlite3.h>\r
+#include "sqlite3x.hpp"\r
+\r
+namespace sqlite3x {\r
+\r
+sqlite3_reader::sqlite3_reader() : cmd(NULL) {}\r
+\r
+sqlite3_reader::sqlite3_reader(const sqlite3_reader &copy) : cmd(copy.cmd) {\r
+       if(this->cmd) ++this->cmd->refs;\r
+}\r
+\r
+sqlite3_reader::sqlite3_reader(sqlite3_command *cmd) : cmd(cmd) {\r
+       ++cmd->refs;\r
+}\r
+\r
+sqlite3_reader::~sqlite3_reader() {\r
+       this->close();\r
+}\r
+\r
+sqlite3_reader& sqlite3_reader::operator=(const sqlite3_reader &copy) {\r
+       this->close();\r
+\r
+       this->cmd=copy.cmd;\r
+       if(this->cmd) ++this->cmd->refs;\r
+\r
+       return *this;\r
+}\r
+\r
+bool sqlite3_reader::read() {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+\r
+       switch(sqlite3_step(this->cmd->stmt)) {\r
+               case SQLITE_ROW:\r
+                       return true;\r
+               case SQLITE_DONE:\r
+                       return false;\r
+               default:\r
+                       throw database_error(this->cmd->con);\r
+       }\r
+}\r
+\r
+void sqlite3_reader::reset() {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+\r
+       if(sqlite3_reset(this->cmd->stmt)!=SQLITE_OK)\r
+               throw database_error(this->cmd->con);\r
+}\r
+\r
+void sqlite3_reader::close() {\r
+       if(this->cmd) {\r
+               if(--this->cmd->refs==0) sqlite3_reset(this->cmd->stmt);\r
+               this->cmd=NULL;\r
+       }\r
+}\r
+\r
+int sqlite3_reader::getint(int index) {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+       if((index)>(this->cmd->argc-1)) throw std::out_of_range("index out of range");\r
+       return sqlite3_column_int(this->cmd->stmt, index);\r
+}\r
+\r
+long long sqlite3_reader::getint64(int index) {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+       if((index)>(this->cmd->argc-1)) throw std::out_of_range("index out of range");\r
+       return sqlite3_column_int64(this->cmd->stmt, index);\r
+}\r
+\r
+double sqlite3_reader::getdouble(int index) {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+       if((index)>(this->cmd->argc-1)) throw std::out_of_range("index out of range");\r
+       return sqlite3_column_double(this->cmd->stmt, index);\r
+}\r
+\r
+std::string sqlite3_reader::getstring(int index) {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+       if((index)>(this->cmd->argc-1)) throw std::out_of_range("index out of range");\r
+       return std::string((const char*)sqlite3_column_text(this->cmd->stmt, index), sqlite3_column_bytes(this->cmd->stmt, index));\r
+}\r
+\r
+std::wstring sqlite3_reader::getstring16(int index) {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+       if((index)>(this->cmd->argc-1)) throw std::out_of_range("index out of range");\r
+       return std::wstring((const wchar_t*)sqlite3_column_text16(this->cmd->stmt, index), sqlite3_column_bytes16(this->cmd->stmt, index)/2);\r
+}\r
+\r
+std::string sqlite3_reader::getblob(int index) {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+       if((index)>(this->cmd->argc-1)) throw std::out_of_range("index out of range");\r
+       return std::string((const char*)sqlite3_column_blob(this->cmd->stmt, index), sqlite3_column_bytes(this->cmd->stmt, index));\r
+}\r
+\r
+std::string sqlite3_reader::getcolname(int index) {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+       if((index)>(this->cmd->argc-1)) throw std::out_of_range("index out of range");\r
+       return sqlite3_column_name(this->cmd->stmt, index);\r
+}\r
+\r
+std::wstring sqlite3_reader::getcolname16(int index) {\r
+       if(!this->cmd) throw database_error("reader is closed");\r
+       if((index)>(this->cmd->argc-1)) throw std::out_of_range("index out of range");\r
+       return (const wchar_t*)sqlite3_column_name16(this->cmd->stmt, index);\r
+}\r
+\r
+}\r
diff --git a/zypp/cache/sqlite3x/sqlite3x_transaction.cpp b/zypp/cache/sqlite3x/sqlite3x_transaction.cpp
new file mode 100644 (file)
index 0000000..f515b96
--- /dev/null
@@ -0,0 +1,61 @@
+/*\r
+       Copyright (C) 2004-2005 Cory Nelson\r
+\r
+       This software is provided 'as-is', without any express or implied\r
+       warranty.  In no event will the authors be held liable for any damages\r
+       arising from the use of this software.\r
+\r
+       Permission is granted to anyone to use this software for any purpose,\r
+       including commercial applications, and to alter it and redistribute it\r
+       freely, subject to the following restrictions:\r
+\r
+       1. The origin of this software must not be misrepresented; you must not\r
+               claim that you wrote the original software. If you use this software\r
+               in a product, an acknowledgment in the product documentation would be\r
+               appreciated but is not required.\r
+       2. Altered source versions must be plainly marked as such, and must not be\r
+               misrepresented as being the original software.\r
+       3. This notice may not be removed or altered from any source distribution.\r
+       \r
+       CVS Info :\r
+               $Author: phrostbyte $\r
+               $Date: 2005/06/16 20:46:40 $\r
+               $Revision: 1.1 $\r
+*/\r
+\r
+#include <sqlite3.h>\r
+#include "sqlite3x.hpp"\r
+\r
+namespace sqlite3x {\r
+\r
+sqlite3_transaction::sqlite3_transaction(sqlite3_connection &con, bool start) : con(con),intrans(false) {\r
+       if(start) begin();\r
+}\r
+\r
+sqlite3_transaction::~sqlite3_transaction() {\r
+       if(intrans) {\r
+               try {\r
+                       rollback();\r
+               }\r
+               catch(...) {\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+void sqlite3_transaction::begin() {\r
+       con.executenonquery("begin;");\r
+       intrans=true;\r
+}\r
+\r
+void sqlite3_transaction::commit() {\r
+       con.executenonquery("commit;");\r
+       intrans=false;\r
+}\r
+\r
+void sqlite3_transaction::rollback() {\r
+       con.executenonquery("rollback;");\r
+       intrans=false;\r
+}\r
+\r
+}\r