Archive for the ‘SQLite’ Category

SQLite 3.7.0 Released – WAL is now available

Wednesday, July 21st, 2010

The official release information can be found [SQLite Release 3.7.0 On 2010 July 22 (3.7.0)]. The summary is that this is a pretty large change compared to previous releases.

  • WAL (Write Ahead Logging) support – this means:
    • Generally faster
    • More concurrency
    • Better disk performance when processing the WAL logs.
    • Cant use network shares or different computers for writing to the same logs.
    • [Complete WAL information can be found here]
  • Query planner enhancement
  • Logical database size is now stored in the database header so that bytes can be appended to the end of the database file

Well done to the SQLite team!

Gareth

PS And for those wondering, I will restart blogging again on a more regular basis very soon, just been unburying myself!

SQLite updated webpage… now has search! Happy New Year!

Friday, January 8th, 2010

It seems the SQLite folks have added a significant, needed and often requested, feature to the SQLite site.  No the change we are talking about has nothing to do with the SQLite engine, but yes I’m talking about the web site. In the top right side of the website there is a new shiny unobtrusive “Search SQLite Docs…” search box.

So for all us who have spent time searching, or had pages pointed out to us :-) , for options  this is an excellent new years present!

Many thanks to the SQLite guys for both their product, and their handy dandy search feature!

SQLite for C# – Part 8 – Loading CSV/Pipe into SQLite via command line

Saturday, September 19th, 2009

Ever wondered how hard it would be to load a CSV file into a SQLite database. I know how I would do it in code, no rocket science needed there! However in this case I wanted to really know the speed of doing this natively and really didn’t want to code anything!

So looking at what SQLite3.exe has too offer it pretty much supports it out of the box. Very nice :-)

Requirements:

  • Loading speed
  • Making the data to consuming applications available asap

While I love C# and frankly its hard to go back to C or C++, sometimes performance trumps the creature comforts we have become accustomed to.

Note: I did this without circling back to a C# implementation as I know the data and performance requirements  are tight and in this case I wanted max performance with no code! The biggest factor to a successful implementation is to ensure you use the tools best for the job, not just the ones you favor in that specific year.

So first things first – create a table to take the input

DROP TABLE IF EXISTS BookSales;
CREATE TABLE IF NOT EXISTS BookSales
(
   Store    int
  ,Date     varchar
  ,OrderReference varchar
  ,Line     int
  ,BookISBN varchar(14)
  ,Quantity int
  ,Price    int
, Primary Key (OrderReference,Line)
);

Next is the magic. We need to load the CSV into the table:

.separator "|"
.import BookSales.txt BookSales

Wow that was easy :-) . You can see we set the separator to be a pipe rather than comma in this case, then the import.

.IMPORT [FileName] [Table]

Now the database is ready to be queried! But if we want to take it just one stage further:

.output SummaryBookSales.csv
SELECT Store, Date, BookISBN, SUM(Quantity), SUM(Price)
FROM BookSales
GROUP BY Store, Date, BookISBN;

Now we output the results of our simple aggregation into a pipe separated output file.

Tying this all together in a single configuration file, which we will call “BookAnalysisLoader.sql”, gives us:

DROP TABLE IF EXISTS BookSales;
CREATE TABLE IF NOT EXISTS BookSales
(
   Store    int
  ,Date     varchar
  ,OrderReference varchar
  ,Line     int
  ,BookISBN varchar(14)
  ,Quantity int
  ,Price    int
, Primary Key (OrderReference,Line)
);

.separator "|"
.import BookSales.txt BookSales

.output SummaryBookSales.csv
SELECT Store, Date, BookISBN, SUM(Quantity), SUM(Price)
FROM BookSales
GROUP BY Store, Date, BookISBN;
.exit

The last piece of the puzzle is the final execution:

sqlite3.exe BookSalesAnalysis.db3 < BookAnalysisLoader.sql

Now we have a newly created database with our analysis data in it, and we have a summary CSV file generated from the output. So we can load the CSV into Excel or another DB, or directly interrogate the DB for more analytical information – and all without coding!

Related Links:

SQLite 3.6.18 has been offically released!

Friday, September 11th, 2009

There are a number of good changes here!

  • Improved query planner:
    • Through better use of statistics
    • Compile time option enables Analyze to better handle the index histograms
    • Additionally it was just plain improved as well!
  • Recursive triggers
  • Delete triggers fire during a REPLACE/MERGE
  • More precise use of caching approaches with the
    • Shared Cache – basically cache the results within the application rather can on each thread. Now configurable on a per-thread basis rather than global.
    • Private – The old way

Well done to the SQLite team! Good stuff

More details can be found [SQLite Release 3.6.18 On 2009 Sep 11 (3.6.18)]