I am working in Xamarin Forms with an iOS app.
The code downloaded successfully an sqlite file and I moved the file to the following location:
/var/mobile/Containers/Data/Application/787D3CB8-01E1-41BB-B786-972534E7F563/Documents/Data/test-file.sqlite
but now when I try to open it with the following code I get a strange error:
SQLite.SQLiteException: 'file is not a database'
The database is also not encrypted
here is my code:
var db = new SQLiteAsyncConnection(_dbPath);
var versionlist = await db.QueryAsync<version_history>("SELECT * FROM version_history ORDER BY id DESC LIMIT 1")
after I do the QueryAsync I get the error, the file is not a database.
but the db object does have the information
Please help me, any ideas?
It turned out it wasn't a real sqlite file after all. It was a zip file but named as a sqlite file and the more crazy is, the fact that it was readable by the sql lite lib, when using SQLiteAsyncConnection.
Even when it was a zip file.
But the moment you fire a query, you will get the error saying that it is not a database.
Related
I have an application which uses a SQLite database to store data locally. I get the path to and open the database using:
string dbPath = System.IO.Path.Combine(FileSystem.AppDataDirectory, "mydatabase")
db = new SQLiteConnection(dbPath);
I have created an example database (example.db3) and copied this to the Resources\Raw folder with the Build Action MauiAsset.
My question is how do I get the path to this database file so I can use
string dbPath = System.IO.Path.Combine("*path to Resources\Raw foldder*", "example.db3");
to get the full path to open the example database.
I have tried searching but the best I can get is using FileSystem.Current.OpenAppPackageFileAsync but this opens the file for stream reading whereas I need to get the path.
Ideally the method would work on all platforms.
It is a known issue about this problem.
You can follow it up here: https://github.com/dotnet/maui/issues/3270.
Thanks for your feedback and support.
In an old VB.NET code (VS 2008) I use this code:
If System.IO.File.Exists(sFilePath) Then
System.IO.File.Delete(sFilePath)
End If
Dim Fs As New System.IO.FileStream(sFilePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write)
Fs.Close()
If the file exists then on this line:
System.IO.File.Delete(sFilePath)
I get this error:
The process cannot access the file because it is being used by another process.
When I manually remove the file, then on this line:
Dim Fs As New System.IO.FileStream(sFilePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write)
I get the error:
The file already exists
Although it doesn't.
The code always (for 8 years now) worked perfectly. Nothing in this part of the code has been changed.
So what is going on here?
I am using this plugin in my ionic project. I am able to open the db. I can see the log:
DB opened: test.db
I created a brand new db using SQL Lite Manager (a firefox plugin) and a table called Products. I then copied the db over to my www folder of my xcode project. I noticed that the extension was called .sqlite, I renamed it to .db. Hopefully that did not create any issues.
Now whenever I try to query that table I get a "No Such Table" - Code 5. I am not sure what that means. The table exists. I tried lower case, upper case etc.., but nothing seems to work.
XCode log window shows me the below log entry, so I assume that its able to find the DB.
open full db path:
/var/mobile/Containers/Data/Application/397075D2-943E-40DC-B076-5C0B5B7D1F42/Documents/test.db
Here is my code:
var db = $cordovaSQLite.openDB("test.db", 1);
var query = "SELECT * FROM 'main'.'Products'";
$cordovaSQLite.execute(db, query).then(function (res)
{ ... });
The second question is how do I check if I was able to open the db successfully from js?
Use the query without the 'main'. You only have 1 database anyway:
var query = "SELECT * FROM Products";
I am using Spreadsheet to parse xls files. It's working great. but today one of my user has uploaded a file and it's getting an error "unknown encoding name - MACINTOSH"
My code is:
book = Spreadsheet.open file_path
sheet1 = book.worksheet 0
This is the excel file which is getting the error:
https://www.dropbox.com/s/jv37pk5rpiy9259/testlisttextnonames2.xls
Can you guys please help me to solve this issue.
Running into the same problem. Here is the best i can deduce:
"Macintosh" is not a known encoding in Ruby 1.9+. Try opening a console and running "Encoding.find('Macintosh')". You'll get the same error.
So what is available? In the console: "Encoding.list". One of the options is MacRoman. I'm guessing this is a close second.
So if we change the mapping in lib/spreadsheet/excel/internals.rb for 10000 and 32768 to map to "MACROMAN", it should work.
Tested locally and it does.
I opened a pull request: https://github.com/zdavatz/spreadsheet/pull/51
Some reference links:
* https://en.wikipedia.org/wiki/Mac_OS_Roman
* http://bugs.python.org/issue843590
I am trying to use
TZipFile.ZipDirectoryContents()
Like so:
TZipFile.ZipDirectoryContents('Test.PCF', WorkingDir);
If I am reading this right, it should save the contents of folder "workingdir" into a file named Test.pcf.
Now when I do this I get error::
Raised exception class EFOpenError with message Cannot open file
...test.pcf. The process cannot access the file because its being used by another process."
Two things confuse me:
It says that it cannot open file. There is no test.pcf yet. I was hoping this would create it.
It says cannot access file. Is this because it's not created yet? Am I using this function wong? If so how would I create a zip file from a folder location?
I tested your code and it failed in the same way as you reported.
I then created an empty zip file manually by running WinZip.
Then ran your code and it ran fine.
It appears that the zip file has to already exist for ZipDirectoryContents to work.
To create a zip file programatically:
myZipFile := TZIpFile.Create;
myZipFile.Open('c:\myfolder\newzipfile.zip', TZipMode.zmWrite);
myZipFile.Close;
myZipFile.Free;
This line will then work:
TZipFile.ZipDirectoryContents('c:\myfolder\newzipfile.zip', WorkingDir);