2011-07-26 94 views
0

我用一個簡單的解決方法解決了我的問題SQLite sqlite3_column_origin_name function,但現在我又遇到了另一個大問題。SQLite3.dll問題x64

我已經與這些進口sqlwrapper:

[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); 

,這是我的executeQuery功能:

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; 
    } 

當我調用sqlite3_column_text(......)我的應用程序崩潰。 我已經探索了dll文件中的函數,並且存在這個入口點「sqlite3_column_text」。

我可以解決我的問題嗎?

編輯:我從http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/1.0.66.0/

文件下載我sqlite3.dll文件是/斌/ 64位之內,我已重新命名爲sqlite3.dll

編輯2:點擊更多的信息,我有:

文件澈contribuiscono阿拉descrizione德爾problema:
C:\用戶\ Utente \應用程序數據\本地的\ Temp \ WERB927.tmp.WERInternalMetadata.xml C:\用戶\ Utente \應用程序數據\本地的\ Temp \ WERD59D.tmp.appcompat.txt
C:\用戶\ Utente \應用程序數據\本地的\ Temp \ WERD5BD.tmp.mdmp

Leggere L'informativa蘇拉在線隱私:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0410

硒L'informativa蘇拉在線隱私不èdisponibile, leggere 克亞離線:C:\ WINDOWS \ SYSTEM32 \ IT-IT \ erofflps.txt

+0

「我能解決我的問題?」也許。第一步是告訴我們一些比「我的應用崩潰」更豐富的信息。 –

+0

你是對的。但我沒有任何錯誤,正如http://stackoverflow.com/questions/6759198/sqlite-sqlite3-column-origin-name-function – CeccoCQ

+0

如果列爲空可能會返回一個空例外,檢查出 – V4Vendetta

回答

0

試試下面的代碼

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

串→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));