API Reference
(1) By Talio (r_s_g_p) on 2022-07-27 14:14:15 [link] [source]
Hi mates, a newbie here.
Is there any reference of the C# SQLite API? I have the help file but it is not complete.
Im looking for the basics (SQLiteConnection, SQLiteCommand, SQLiteCommandBuilder...) cause im in my first steps.
There are several web pages but are just '1-2-3' and I want a full reference of the API to go progressive deeper.
Ty.
(2) By Gunter Hick (gunter_hick) on 2022-07-28 05:30:02 in reply to 1 [source]
SQLite has a C Api, the rest are wrappers, only some of which are maintained by SQLite dev. The rest are third party bindings maintained by their respective developers. Which "the C# SQLite API" are you referring to?
(3) By mistachkin on 2022-07-29 13:37:52 in reply to 1 [link] [source]
(4.1) By Chris Locke (chrisjlocke1) on 2022-07-29 17:02:58 edited from 4.0 in reply to 1 [link] [source]
cause im in my first steps
This seems like chopping down trees with a penknife.
If you have c# and just want to do an application with sqlite access, do you just want 'quick 'n easy' ?
Go to https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki and widen your eyes as you scroll further down .. and down .. and down ..
The link you want is actually 'Precompiled Binaries for 64-bit Windows (.NET Framework 4.6)' (even if you're doing a .Net 6 app). Also download the x64 flavour. Then follow the path structure at the top of the page:
<bin>\App.exe
<bin>\App.dll
<bin>\System.Data.SQLite.dll (taken from the x86 .zip is fine)
<bin>\x86\SQLite.Interop.dll (taken from the x86 .zip)
<bin>\x64\SQLite.Interop.dll (taken from the x64 .zip)
Slap a reference in your app to the system.data.sqlite.dll
Then create an app. I normally create a class to hold the database, but for a 'hello world' example, slap this in a button. (This is nasty vb.net code, but its easy to convert to c#...)
Imports System.Data.SQLite
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connection As New SQLiteConnection("data source=log.db")
connection.Open()
Dim sql1 As String = $"insert into log
(date,type,detail,sessionId)
values ('{Now:yyyy-MM-dd HH:mm}','d','This is a test entry. Hello World',0)"
Dim command = New SQLiteCommand(sql1, connection)
Dim result1 = command.ExecuteNonQuery
'what was the id number?
command = New SQLiteCommand("SELECT last_insert_rowid()", connection)
Dim result2 = command.ExecuteScalar
End Sub
End Class
This assumes your database file is called 'log.db' (which it won't) and have five fields (which it won't) and be set up like mine (which it won't).
Assumming it is, it's easy to connect to the database, craft some SQL and execute the query. Obviously this has no error trapping or use parameters, which is all supported.
It's easier doing this than the raw API route... unless of course you WANT to go the full API route ...