i0 / csharp-sqlite

Automatically exported from code.google.com/p/csharp-sqlite
Other
1 stars 0 forks source link

Creating a Unique Index within a Transaction causes MethodAccessException #150

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
This code fails:
using (var c = new SqliteConnection("Data Source=DuplicatePrimaryKey.db3"))
{
    c.Open();
    using (var cmd = c.CreateCommand())
    {
        var trans = c.BeginTransaction();
        cmd.CommandText = "CREATE TABLE [IndexedTable] ([Indexed] integer NOT NULL);";
        cmd.ExecuteNonQuery();

        cmd.CommandText = "CREATE UNIQUE INDEX [IX_TabelIndex] on [IndexedTable] ([Indexed]);";
        cmd.ExecuteNonQuery(); // fails here
        trans.Commit();
    }
}

What is the expected output? What do you see instead?
System.MethodAccessException was unhandled
  Message=Attempt to access the method failed: System.IO.Path.GetTempPath()
  StackTrace:
       at Community.CsharpSqlite.Sqlite3.getTempname(Int32 nBuf, StringBuilder zBuf)
       at Community.CsharpSqlite.Sqlite3.winOpen(sqlite3_vfs pVfs, String zName, sqlite3_file pFile, Int32 flags, Int32& pOutFlags)
       at Community.CsharpSqlite.Sqlite3.sqlite3OsOpen(sqlite3_vfs pVfs, String zPath, sqlite3_file pFile, Int32 flags, Int32& pFlagsOut)
       at Community.CsharpSqlite.Sqlite3.pagerOpentemp(Pager pPager, sqlite3_file& pFile, Int32 vfsFlags)
       at Community.CsharpSqlite.Sqlite3.openSubJournal(Pager pPager)
       at Community.CsharpSqlite.Sqlite3.subjournalPage(PgHdr pPg)
       at Community.CsharpSqlite.Sqlite3.pager_write(PgHdr pPg)
       at Community.CsharpSqlite.Sqlite3.sqlite3PagerWrite(PgHdr pDbPage)
       at Community.CsharpSqlite.Sqlite3.allocateBtreePage(BtShared pBt, MemPage& ppPage, UInt32& pPgno, UInt32 nearby, Byte exact)
       at Community.CsharpSqlite.Sqlite3.btreeCreateTable(Btree p, Int32& piTable, Int32 createTabFlags)
       at Community.CsharpSqlite.Sqlite3.sqlite3BtreeCreateTable(Btree p, Int32& piTable, Int32 flags)
       at Community.CsharpSqlite.Sqlite3.sqlite3VdbeExec(Vdbe p)
       at Community.CsharpSqlite.Sqlite3.sqlite3Step(Vdbe p)
       at Community.CsharpSqlite.Sqlite3.sqlite3_step(Vdbe pStmt)
       at Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteStatement(Vdbe pStmt, Int32& cols, IntPtr& pazValue, IntPtr& pazColName)
       at Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteStatement(Vdbe pStmt)
       at Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteReader(CommandBehavior behavior, Boolean want_results, Int32& rows_affected)
       at Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteNonQuery()
       at Test.WP.MainPage.MainPage_Loaded(Object sender, EventArgs e)
       at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

What version of the product are you using? On what operating system?
Windows Phone Emulator

Please provide any additional information below.
  File : os_win_c.cs
  Line : 2507

Code:
#if SQLITE_WINRT
      zBuf.Append( Path.Combine(ApplicationData.Current.LocalFolder.Path, SQLITE_TEMP_FILE_PREFIX + zRandom.ToString()) );
#else
      zBuf.Append( Path.GetTempPath() + SQLITE_TEMP_FILE_PREFIX + zRandom.ToString() ); // here
#endif

Original issue reported on code.google.com by mattleib...@gmail.com on 30 Mar 2012 at 2:08

GoogleCodeExporter commented 8 years ago
Silverlight does not allow the use of GetTempFilename to get temporary 
filename. IsolatedStorage will have to be used.

Original comment by mattleib...@gmail.com on 30 Mar 2012 at 2:11

GoogleCodeExporter commented 8 years ago
Fixed with changeset #80

Original comment by noah.hart@gmail.com on 18 May 2012 at 11:19

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
We're randomly seeing this exception in our Windows Phone app with rev 
ca3c79393adf (from December 2013). Randomly meaning that 99% of the time 
everything is OK, but we've received few error reports from our users:

[ExceptionMessage]:[Attempt to access the method failed: 
System.IO.Path.GetTempPath()]
[StackTrace]:[
   at Community.CsharpSqlite.Sqlite3.getTempname(Int32 nBuf, StringBuilder zBuf)
   at Community.CsharpSqlite.Sqlite3.winOpen(sqlite3_vfs pVfs, String zName, sqlite3_file pFile, Int32 flags, Int32& pOutFlags)
   at Community.CsharpSqlite.Sqlite3.sqlite3OsOpen(sqlite3_vfs pVfs, String zPath, sqlite3_file pFile, Int32 flags, Int32& pFlagsOut)
   at Community.CsharpSqlite.Sqlite3.pagerOpentemp(Pager pPager, sqlite3_file& pFile, Int32 vfsFlags)
   at Community.CsharpSqlite.Sqlite3.openSubJournal(Pager pPager)
   at Community.CsharpSqlite.Sqlite3.subjournalPage(PgHdr pPg)
   at Community.CsharpSqlite.Sqlite3.pager_write(PgHdr pPg)
   at Community.CsharpSqlite.Sqlite3.sqlite3PagerWrite(PgHdr pDbPage)
   at Community.CsharpSqlite.Sqlite3.insertCell(MemPage pPage, Int32 i, Byte[] pCell, Int32 sz, Byte[] pTemp, UInt32 iChild, Int32& pRC)
   at Community.CsharpSqlite.Sqlite3.sqlite3BtreeInsert(BtCursor pCur, Byte[] pKey, Int64 nKey, Byte[] pData, Int32 nData, Int32 nZero, Int32 appendBias, Int32 seekResult)
   at Community.CsharpSqlite.Sqlite3.sqlite3VdbeExec(Vdbe p)
   at Community.CsharpSqlite.Sqlite3.sqlite3Step(Vdbe p)
   at Community.CsharpSqlite.Sqlite3.sqlite3_step(Vdbe pStmt)
   at SQLite.SQLite3.Step(Vdbe stmt)
   at SQLite.PreparedSqlLiteInsertCommand.ExecuteNonQuery(Object[] source)
   at SQLite.SQLiteConnection.Insert(Object obj, String extra, Type objType)
   at SQLite.SQLiteConnection.Insert(Object obj)

Original comment by mijap...@gmail.com on 5 Feb 2013 at 6:26