thx for your response !!

Robert Simpson a écrit :

----- Original Message ----- From: "Gregory Letellier" <[EMAIL PROTECTED]>


i'm trying tu use sqli3 with vb. net
he create the db but not the table..
what is the mistake ?

i've this code

Imports System.Runtime.InteropServices

Public Class Form1

       <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
   Public Structure sqlite_callback
       Public Void As Long
       Public I1 As Long
       Public s1 As String
       Public s2 As String
   End Structure

   Public Declare Function sqlite3_open Lib "sqlite3.dll" (ByVal
Filename As String, ByRef Handle As Long) As Long
   Public Declare Function sqlite3_exec Lib "sqlite3.dll" (ByVal Handle
As Long, ByVal Query As String, ByRef CallbackFunction As
sqlite_callback, ByRef CallBackArgs As Long, ByRef Erreur As String) As Long
   Public Declare Function sqlite3_close Lib "sqlite3.dll" (ByVal
Handle As Long) As Long
   Public Declare Function sqlite3_errmsg Lib "sqlite3.dll" (ByVal
Handle As Long) As String

       Public Sub Main()

       Dim lRet As Long
       Dim lHandle As Long
       Dim sErreur As String
       Dim sSQL As String

       lRet = sqlite3_open("c:\test.db", lHandle)

       sSQL = "CREATE Table Toto(titi varchar(15));"
       lRet = sqlite3_exec(lHandle, sSQL, Nothing, Nothing, sErreur)

       sqlite3_close(lHandle)
   End Sub
End Class


Lots of problems here ... My VB is rusty, but here goes:

1. Don't bother declaring the callback struct -- you cannot do any form of callbacks in .NET with SQLite without major hacking. SQLite's callbacks are expected to be "cdecl" and .NET callbacks are always "stdcall" and you will get stack errors if you even attempt it. The ADO.NET 2.0 provider for SQLite does it, but I had to go through hoops.

2. sqlite3_exec is declared incorrectly. The errormessage is a char **, which is a pointer to a pointer. Getting this out of sqlite into .NET is not straightforward. You'll have to use ByRef IntPtr and use the Marshal class to convert it to a string.

3. sqlite3_open and sqlite3_exec are both sortof declared and processed incorrectly. Those functions expect UTF-8 encoded strings, and you are passing "string" to them which .NET will at best translate to MBCS ANSI strings -- which means no international support. For added safety you should declare those API functions with the CharSet=ANSI attribute to make absolutely sure .NET gives sqlite ANSI strings instead of UNICODE strings. It's still wrong, but its close enough for English-only.

4. All sqlite API functions are declared as cdecl, and without instructions to the contrary, .NET will try and call them as stdcall which means after every call .NET will have to perform stack fixups. It won't error out your program per-se, but it will be a performance hit. There's an attribute you can use to change the calling conventions of the API declaration, but I can't remember it off the top of my head.

Robert




Reply via email to