我在SQLite sqlite3_column_origin_name function解决了我的问题,只是简单地解决了问题,但现在我又遇到了一个大问题。
我有一个带有这些导入的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文件文件在/ bin / x64中,我已将其重命名为sqlite3.dll
编辑2:点击我有的更多信息:
文件che contribuiscono alla描述del problema:
C:\ Users \用户Utente \应用程序数据\本地的\ Temp \ WERB927.tmp.WERInternalMetadata.xml C:\ Users \用户Utente \应用程序数据\本地的\ Temp \ WERD59D.tmp.appcompat.txt
C:\用户\ Utente \应用程序数据\本地\ TEMP \ WERD5BD.tmp.mdmpLeggere l'informativa sulla在线隐私:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0410Se l'informativa sulla privacy onlinenonèdisponibile,leggere 离线quella:C:\ Windows \ system32 \ it-IT \ erofflps.txt
答案 0 :(得分:0)
尝试以下代码
[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));