hardborn / csharp-sqlite

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

System.IO.Path.GetTempPath() throws exceptions #172

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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();
    }
}

System.Security.SecurityException was unhandled by user code
  Message=File operation not permitted. Access to path '' is denied.
  StackTrace:
       at System.IO.FileSecurityState.EnsureState()
       at System.IO.Path.GetTempPath()
       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 Mono.Data.Sqlite.SQLite3.Step(SqliteStatement stmt)
       at Mono.Data.Sqlite.SqliteDataReader.NextResult()
       at Mono.Data.Sqlite.SqliteDataReader..ctor(SqliteCommand cmd, CommandBehavior behave)
       at Mono.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
       at Mono.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
       at Mono.Data.Sqlite.Orm.SqliteSession.Execute(String query, Object[] args)
       at Mono.Data.Sqlite.Orm.SqliteSession.<>c__DisplayClass2a.<CreateTable>b__29(Index index)
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Linq.Enumerable.Sum(IEnumerable`1 source)
       at System.Linq.Enumerable.Sum[TSource](IEnumerable`1 source, Func`2 selector)
       at Mono.Data.Sqlite.Orm.SqliteSession.CreateTable(TableMapping map)
       at Mono.Data.Sqlite.Orm.SqliteSession.CreateTable[T]()
       at Mono.Data.Sqlite.Orm.Tests.CreateTableTest.CreateIndexedTable()

I have created a patch that solve this issue. I have tested it for the 
silverlight part and it should work for windows phone. Do we need to support 
WinRT in the library since the official sqlite library does this?

I haven't tested on the other platforms.

The general change was from: 
  zBuf.Append( Path.GetTempPath() + SQLITE_TEMP_FILE_PREFIX + zRandom.ToString() );
to:
  zBuf.Append( Path.Combine(sqlite3_temp_directory, SQLITE_TEMP_FILE_PREFIX + zRandom.ToString()) );

ie: correctly use the sqlite3_temp_directory variable instead of path.gettemp. 
But if I look at the WinRT implementation, should this also be changed?

Original issue reported on code.google.com by mattleib...@gmail.com on 28 Oct 2012 at 11:21

Attachments:

GoogleCodeExporter commented 9 years ago
This issue is almost the same as issue #150
https://code.google.com/p/csharp-sqlite/issues/detail?id=150

But I think the error may be dfferent

Original comment by mattleib...@gmail.com on 28 Oct 2012 at 11:22

GoogleCodeExporter commented 9 years ago

Original comment by noah.hart@gmail.com on 25 Nov 2012 at 3:00

GoogleCodeExporter commented 9 years ago
This should be fixed now in revision 56416abacd80.

Original comment by mattleib...@gmail.com on 17 Mar 2013 at 6:53

GoogleCodeExporter commented 9 years ago
about this,i think it can' be fixed,i still get this bug .

SQL logic error or missing database@   at 
Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteStatement(Vdbe pStmt, 
Int32& cols, IntPtr& pazValue, IntPtr& pazColName)   at 
Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteReader(CommandBehavior 
behavior, Boolean want_results, Int32& rows_affected)   at 
Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteNonQuery()   at 
ebMobile.SFA.DAL.DAL_VISIT.DeleteVisitById(VISITVIEW visitview)  Date: 
130816133056

Original comment by liu428z...@gmail.com on 16 Aug 2013 at 7:19

GoogleCodeExporter commented 9 years ago
but i get the source code from this website:
http://wp7sqlite.codeplex.com/
NOTE:
I also get the latest source code from 
google[https://code.google.com/p/csharp-sqlite/],but this project can't be 
released,debug model is ok.

Original comment by liu428z...@gmail.com on 16 Aug 2013 at 7:48