0
votes

I've solved my problem at SQLite sqlite3_column_origin_name function with a simply workaround but now I've an another big problem.

I've a sqlwrapper with these imports:

    [DllImport("sqlite3.dll", EntryPoint = "sqlite3_column_int")]
    static extern int sqlite3_column_int(IntPtr stmHandle, int iCol);

    [DllImport("sqlite3.dll", EntryPoint = "sqlite3_column_text")]
    static extern string sqlite3_column_text(IntPtr stmHandle, int iCol);

    [DllImport("sqlite3.dll", EntryPoint = "sqlite3_column_double")]
    static extern double sqlite3_column_double(IntPtr stmHandle, int iCol);

and this is my ExecuteQuery function:

    public DataTable ExecuteQuery(String query)
    {

        SQLiteWrapper.query = query;

        if (!_open)
            throw new SQLiteException("SQLite database is not open.");

        //prepare the statement
        IntPtr stmHandle = IntPtr.Zero;
        try
        {
            stmHandle = Prepare(query);
        }
        catch(Exception e)
        {
            Log.e(e.Message);
            return null;
        }


        // Prevensione sul out of memory
        if(stmHandle == IntPtr.Zero) 
        {
            return null;
        }

        //get the number of returned columns
        int columnCount = sqlite3_column_count(stmHandle);

        DataTable dTable = null;
        try
        {
            //create datatable and columns
            dTable = new DataTable();
            for (int i = 0; i < columnCount; i++)
            {
                try
                {
                    ArrayList selections = Utils.getQuerySelection(query);
                    foreach(String s in selections) 
                    {
                        dTable.Columns.Add(s);
                    }
                    //Workaround for sqlite3_column_origin_name

                    //dTable.Columns.Add("_id");
                   //dTable.Columns.Add(sqlite3_column_origin_name(stmHandle, i));
                }
                catch(Exception e) 
                {

                }
            }

            //populate datatable
            while (sqlite3_step(stmHandle) == SQLITE_ROW)
            {
                object[] row = new object[columnCount];
                for (int i = 0; i < columnCount; i++)
                {
                    switch (sqlite3_column_type(stmHandle, i))
                    {

                        case SQLITE_INTEGER:
                            // WORKS CORRECTLY!!!!
                            row[i] = sqlite3_column_int(stmHandle, i);
                            break;
                        case SQLITE_TEXT:
                            // ERROR!!!!!!!!!!!!!!!!!!!!!!
                            row[i] = sqlite3_column_text(stmHandle, i);
                            break;
                        case SQLITE_FLOAT:
                            row[i] = sqlite3_column_double(stmHandle, i);
                            break;
                    }
                }
                dTable.Rows.Add(row);
            }
        }
        catch(AccessViolationException ave)
        {
            Log.e("SqliteWrapper - AccessViolationException - " + ave.Message + ":" + query);
            return null;
        }

        // Se ci sono stati errori allora torna null e ritenta la query
        Boolean finalized = Finalize(stmHandle);
        if(!finalized) 
        {
            return null;
        }
        return dTable;
    }

When I invoke the sqlite3_column_text(...) my app crashes. I've explored functions within dll file and this entrypoint "sqlite3_column_text" exists.

Can I solve my problem?

EDIT: I download my sqlite3.dll file from http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/1.0.66.0/

File is within /bin/x64 and I've renamed it into sqlite3.dll

EDIT 2: Clicking on more info I have:

File che contribuiscono alla descrizione del problema:
C:\Users\Utente\AppData\Local\Temp\WERB927.tmp.WERInternalMetadata.xml C:\Users\Utente\AppData\Local\Temp\WERD59D.tmp.appcompat.txt
C:\Users\Utente\AppData\Local\Temp\WERD5BD.tmp.mdmp

Leggere l'informativa sulla privacy online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0410

Se l'informativa sulla privacy online non è disponibile, leggere quella offline: C:\Windows\system32\it-IT\erofflps.txt

1
"Can I solve my problem?" Maybe. Step 1 would be to tell us something more informative than "my app crashes". - David Heffernan
Click on the button on the dialog that offers you more information. - David Heffernan
Any reason why you're not using the SQLite3 .NET wrapper instead of hand-coding everything yourself? - system.data.sqlite.org/index.html/doc/trunk/www/index.wiki - Lasse V. Karlsen
But isn't ADO.NET already installed if you have .NET? You don't need to install anything for that library, just add a reference to the correct dll and bundle that with your application. - Lasse V. Karlsen
You can easily run setup on your machine, and still only add a reference to that file, and bundle it with your application. But if you want to avoid installing anything even on your machine, then yes, download the binaries. And don't use sqlite.phxsoftware.com, that provider is old, use the one on system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki - Lasse V. Karlsen

1 Answers

0
votes

try following code

[DllImport("sqlite3.dll", EntryPoint = "sqlite3_column_text")]
    static extern string sqlite3_column_text(IntPtr stmHandle, int iCol);

string → IntPtr

[DllImport("sqlite3.dll", EntryPoint = "sqlite3_column_text")]
static extern IntPtr sqlite3_column_origin_name(IntPtr stmHandle, int iCol);

row[i] = Marshal.PtrToStringAnsi(sqlite3_column_text(stmHandle, i));