请参阅下面在 Monotouch 中使用 Sqlite 的代码。它代表了许多方法中的一种,并且看起来都一样。一切都清理干净了吗?在 Sqlite 文档中,我读到我应该完成每个准备好的语句,但我找不到匹配的调用。那么,我错过了什么吗?
据我所知,我正在打开关闭并正确处理所有内容。尽管如此,我还是随机从 Sqlite收到malloc() 错误。这是最近开始的,所以它也可能是 MT 本身的 Sqlite 版本中的一个问题,因为我的代码没有改变。
using ( SqliteConnection oConn = this.CreateDBMSConnection() )
{
oConn.Open ();
using ( SqliteCommand oCmd = new SqliteCommand (
"SELECT CollaborationItems.*, CollaborationParticipants.intStatus AS intParticipantStatus FROM CollaborationItems " +
"LEFT JOIN CollaborationParticipants ON CollaborationItems.intItemID = CollaborationParticipants.intItemID " +
"WHERE CollaborationItems.intID = @intD", oConn ) )
{
oCmd.Parameters.AddWithValue( "@intID", iItemID );
using ( SqliteDataReader oReader = oCmd.ExecuteReader ( ) )
{
while ( oReader.Read( ) )
{
// [...] - some code omitted.
// The next call again create a DMBS connection, has similar using etc.
oItem.Participants = this.GetEventParticipants(oItem);
}
oReader.Close( );
}
}
oConn.Close( );
}
这是我收到的例外:
Mono.Data.Sqlite.SqliteException: malloc() 在 Mono.Data.Sqlite.SQLite3.Prepare 内存不足 (Mono.Data.Sqlite.SqliteConnection cnn, System.String strSql, Mono.Data.Sqlite.SqliteStatement previous, UInt32 timeoutMS, System.String& strRemain) [0x0022a] 在 /Developer/MonoTouch/Source/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs:343 在 Mono.Data.Sqlite。 SqliteCommand.BuildNextCommand () [0x00019] 在 /Developer/MonoTouch/Source/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteCommand.cs:230