0

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

Community
  • 1
  • 1
CeccoCQ
  • 3,746
  • 12
  • 50
  • 81
  • "Can I solve my problem?" Maybe. Step 1 would be to tell us something more informative than "my app crashes". – David Heffernan Jul 26 '11 at 10:09
  • You're right. But I haven't any error, exactly as http://stackoverflow.com/questions/6759198/sqlite-sqlite3-column-origin-name-function – CeccoCQ Jul 26 '11 at 10:13
  • If the column is null might return a Null exception, check that out – V4Vendetta Jul 26 '11 at 10:13
  • I didn't have any return. I have only a crash. Please, see edit. – CeccoCQ Jul 26 '11 at 10:15
  • 1
    Click on the button on the dialog that offers you more information. – David Heffernan Jul 26 '11 at 10:21
  • @David: This dialog doesn't display any important info. But I edit my question. – CeccoCQ Jul 26 '11 at 10:25
  • The dialog does display important information. Details of the crash are in the files referenced by the dialog. – David Heffernan Jul 26 '11 at 10:41
  • I didn't find these files into the path. – CeccoCQ Jul 26 '11 at 10:46
  • 1
    Any reason why you're not using the SQLite3 .NET wrapper instead of hand-coding everything yourself? - http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki – Lasse V. Karlsen Jul 26 '11 at 11:02
  • Because I don't want install ADO.NET provider as software, I want only add the dll as project reference. – CeccoCQ Jul 26 '11 at 11:05
  • 1
    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 Jul 26 '11 at 13:19
  • I have understand what you mean, but when I download from http://sqlite.phxsoftware.com/ the provider, I see setup.exe. Maybe I should download only binaries, isn't it? – CeccoCQ Jul 27 '11 at 07:03
  • 1
    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 http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki – Lasse V. Karlsen Jul 27 '11 at 12:33

1 Answers1

0

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));
Amicable
  • 3,115
  • 3
  • 49
  • 77
lixch
  • 1