Code Monkey home page Code Monkey logo

sqliteforexcel's Introduction

Overview

SQLite is a small, easy-to-use, open-source SQL database engine. This project, SQLite for Excel, is a lightweight wrapper to give access to the SQLite3 library from VBA. It provides a high-performance path to the SQLite3 API functions, preserving the semantics of the SQLite3 library calls and allowing access to the distributed SQLite3.dll without recompilation.

Release Details

The current release has the following parts:

Distribution directory

  • ChangeLog.txt contains details of the changes in every version.
  • SQLite3_StdCall.dll is a small and very simple C .dll that makes it possible to use the standard SQLite3 .dll from VBA. It just passes calls from VBA on to SQLite without any change in the parameters, but this allows the StdCall calling convention that VB6 and VBA is limited to.
  • SQLiteForExcel.xls contains the two VBA modules:
    • SQLite3.bas VBA module has all the VBA Declares, and does the parameter and string conversions. It exposes a number of SQLite3xxxx functions. These map as directly as possible to the SQLite C API, with no change in the semantics. Although I have not exposed the whole API, most of the core interface is included, in particular the prepared statement, binding, retrieval and backup functions. Date values are stored as Julian day real numbers in the database.
    • SQLite3Demo.bas VBA module has tests that serve as nice examples of how to use the SQLite3xxxx functions.
  • SQLiteForExcel_64.xlsm contains 64-bit versions of the two VBA modules in a version that supports both 32-bit and 64-bit versions of Excel.The corresponding {"Sqlite3Demo_64.bas"} module shows how to target both 32-bit and 64-bit Excel with the same VBA code (some #Ifs are required). (Note that the default install of Office is always the 32-bit version, even on a 64-bit version of Windows. Only if the 64-bit version of Office has been specifically selected will the 64-bit modules be required.)
  • sqlite3.dll is a copy of SQLite version 3.11.1, as downloaded from the SQLite website.
  • x64\SQLite3.dll is a 64-bit build of SQLite 3.11.1.

Source directory

  • SQLite3VBAModules contains the four VBA modules described about (32-bit and 64-bit).
  • SQLite3_StdCall contains the C language source code for the library described above.

Getting Started

  • Download the release archive .zip file from https://github.com/govert/SQLiteForExcel/releases.
  • Unzip the download to a convenient location.
  • Open the Distribution\SQLiteForExcel.xls file.
  • Open the VBA Editor (Alt+F11).
  • Note the SQLite3 module which contains the declarations and helper functions to access SQLite.
  • Examine and run the example test code in the SQLite3Demo module.
  • Find the documentation for the SQLite functions here: http://sqlite.org/cintro.html. The complete query language for SQLite is documented here: http://sqlite.org/lang.html.

Sample projects

Related Projects

  • The SQLite home is at http://www.sqlite.org and the most recent version of the SQLite3.dll library can be found here http://www.sqlite.org/download.html.
  • To create User-Defined Functions (UDFs) for Excel using C#, VB.NET or F#, have a look at my Excel-DNA project. It provides free and easy integration of .NET with Excel.
  • For access to SQLite from .NET I recommend:
    • the official System.Data.SQLite is a full-featured ADO.NET driver with full Linq and Entity Framework support, or
    • the sweet-looking sqlite-net, a light-weight wrapper with attribute-based object-to-database mapping and some Linq support.

Support

Create a new GitHub Issue. You are also welcome to contact me directly at mailto:[email protected] with questions, comments or suggestions.

sqliteforexcel's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqliteforexcel's Issues

File Access

Is there a secret in regard to file access (Excel-Security-Options)?
My file access fails.

SQLite3Open returned 0 SQLite3OpenV2 returned 0 SQLite3Close V2 returned 0 SQLite3Close returned 0 SQLite3Open returned 0 SQLite3OpenV2 returned 0 SQLite3Close V2 returned 0 SQLite3Close returned 0

Hey, thank you!

Any dependency?

Hi, I am trying to run the test but I get Error 53 FIle not found SQLite3_Stdcall.dll" Is there any dependency I am missing? I tried hard coding the dll directory but doesn't seem to help.

Support for encrypted databases

I use this wrapper in order to upload SQLite data to Excel. For security reasons, SQLite containers that I manage has password now (It was given by SQLite Browser with Cipher). The wrapper can not open these databases. Can you write an instruction that open encrypted databases, with a given password? Parameters of this procedure or function are the DB Handler, the DB username and password.
Thanks in advance for your help.

Timestamp support

Hi,
i'm working with your .bas with excel. After lots of tries i found that you have not insert a stdcall for bind timestamp, because your stdcall for bind date converts date value in double.
There is a way to solve this issue?
Thank you!

Issue with latest SQlite DLL

I have a Excel VBA that works fine with the SQLITE DLL downloaded together with the SQLiteforExcel package. But if I replace them with the latest ones (3.33) I get error during sqlite3close operation. (Error 5). It seems some locks are not getting released.

Is it not advised to change DLL versions or is there a change in behaviour in newer SQLite?

Sorry for posting something that is not directly related to this module and I am using unsupported DLL obviously, but just wanted to raise this in case..

64bit version crashes

I just tried running the demo routine, and it crashed Excel four out of four times. I stepped through the code, and it crashes on the operative line of the SQLite3BackupStep routine.

I believe this is a result of the sqlite3_backup_init API declaration, which appears to return a Long data type, which is then passed to the BackupStep routine as the backuphandle (LongPtr). I changed the sqlite3_backup_init API declaration to return a LongPtr instead (as below) and it no longer crashes.

Private Declare PtrSafe Function sqlite3_backup_init Lib "SQLite3" (ByVal hDbDest As LongPtr, ByVal zDestName As LongPtr, ByVal hDbSource As LongPtr, ByVal zSourceName As LongPtr) As LongPtr

Please explain how SQLiteForExcel_64.xlsmworks in a simple example

So how can I use this nice macro? the excel sheet seems to be blank. I'm not sure what this point means: "Examine and run the example test code in the SQLite3Demo module." what should I expect after I "run" the Sqlite3 VBA? I chose AllTests and it seems to execute silently but so what?
Could you please add a very simple example to use this macro to connect to a SQLite database with one table? All I want is to have a drop down list in excel that pulls values from the SQLite table. The XLSQLite.xlam example at http://www.gatekeeperforexcel.com/other-freebies.html seems useful but it only works for 32 bits and I have 64 bits. I dont want the complex GUI part. Just simple.
Thank you

sqlite dot-commands

Hi,

Many thanks for this work.
However, is it possible to use dot-commands in vba script code? i.e: .import file.csv

Many thanks

How to add SQLite Amalgamation function to SQLiteForExcel

I found that sqlite.com provide an extension file for adding extra function on sqlite, such as SQRT(). This function is really important for my daily operation. But I dont know how to add the extension to SQLiteForExcel. Is it possible to add those extension to SQLiteForExcel?

Thank you very much for contributing this amazing package. I am so happy to convert my old dbf files to sqlite and operating them by excel.

Latest VBA engine compatibility

Would this still work on the latest vba engine? I know there were some changes to how 64 bit vba needed to use pointers and call windows api functions...

Implement Int64 support

From an email suggestion:

I have noted that you have commented the following functions as untested:
sqlite3_stdcall_column_int64 and
sqlite3_stdcall_bind_int64

I have successfully managed to use your project to read and write full sized signed 64 bit integers using the little known decimal data type:
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/data-types/decimal-data-type

I have hence created the following functions:

Public Function SQLite3ColumnInt64(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Variant
SQLite3ColumnInt64 = CDec(sqlite3_stdcall_column_int64(stmtHandle, ZeroBasedColIndex)) * 10000
End Function

and

Public Function SQLite3BindInt64(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Variant) As Long
SQLite3BindInt64 = sqlite3_stdcall_bind_int64(stmtHandle, OneBasedParamIndex, CCur(Value * 0.0001))
End Function

In the first function, we read in the 64 bits into a currency data type as per your sqlite3_stdcall_column_int64. As I am sure you are aware this is a 2's compliment signed 64 bit integer with an annoying decimal place four numbers in.
To convert this to a decimal we use CDec and then multiply by 1000. You will note that the return type is a variant. This is because you cannot declare a decimal in VBA directly.
I.e. you cannot say Dim x as Decimal. Instead you have to say Dim x as Variant: x= CDec(0)

The second function reverses the process by taking in a variant (be this a Byte, Single, Double, Integer, Long, LongLong, Currency or Decimal), dividing by 10000 and then converting to a currency value before calling your sqlite3_stdcall_bind_int64.

We can easily convert an unsigned decimal to a signed decimal.

Private Function unsignedDec(signedDec As Variant) As Variant
Dim twoTo64 As Variant: twoTo64 = CDec(2 ^ 32) * CDec(2 ^ 32)
If signedDec < 0 Then
unsignedDec = signedDec + twoTo64
Else
unsignedDec = signedDec
End If
End Function

Sub testDec()

Dim x As Variant: x = CDec(-1)
Debug.Print unsignedDec(x)

End Sub

far slower reading data from cursor in Office 365 due to character encoding

My company recently updated to office 365 and all my tools got vastly slower using this. Specifically running the DLL api functions to step thru the cursor, read the datatype and convert is many times slower. It's slightly less noticeable when data is only numeric, but I believe it's still slower. I believe this problem is related to the text encoding.

IOW, sqlite db works just as fast, but when you return a lot of data, it takes a lot longer to read it in to an array stepping thru the cursor (so to speak, using the step function). I'm not sure what is going on. I haven't found a fix yet, but it's sad because you can write such amazing solutions using this .. I read all excel tables in automatically to a database in memory as they're added. You'd never even know you basically have an excel db in RAM and I wrote my own sql editor with VBA forms.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.