I have started playing around with Berkeley DB. This one is really interesting, but I am facing one problem.
While creating the Environment we create it like this -
Environment env = new Environment(new File("./bdb"), envConfig);
It initially threw an exception saying "bdb" location was not found. I created the location and it all worked.
My question is how would I set up berkeley DB to create this directory for me if it does not exist. I actually checked at the config method SetAllowCreate(boolean flag) .. but its functionality is different.
Any help would be appreciated.
Thanks.
You can do -
File file = new File("file path goes here");
// Either the file exists or mkdirs is successful
if (file.exists() || file.mkdirs()) {
Environment env = new Environment(file, envConfig);
}
I actually ended up doing something like this (not sure whether it is right solution but it works)
boolean x = new file("./bdb.data").mkdir();
Environment env = new Environment(new File("./bdb"), envConfig);
Related
I've used:-
$db = new \IP2Location\Database('./database/IP2LOCATION-LITE-DB3.IPV6.BIN', \IP2Location\Database::FILE_IO);
it seems to work OK.
IP2 docs. says "Class Database, Expects 2 input parameters"
Full path of IP2Location BIN data file. -- OK
File Open Mode. -- Why does it also need "\IP2Location\Database::" ?
Tried not using "\IP2Location\Database::FILE_IO" just using "FILE_IO".
I'm interested in importing an external SQLite database to my project.
When using the QT Quick Local Storage:
LocalStorage.openDatabaseSync("QQmlExampleDB", "1.0", "The Example QML SQL!", 1000000);
The problem is that, the program generates a NEW database, and if it's possible I'm interested in open an existing database.
Any idea?
Thank you very much!
Thanks all of you, with the information you have got me I could solve my problem, all the things I have had to do are:
First of all in main.cpp I set my offline Storage Path:
engine.setOfflineStoragePath(QString("./"));
Then I also add this code:
QDir dir("./Databases");
if (!dir.exists()) {
dir.mkpath(".");
}
QString new_name = QString(QCryptographicHash::hash(("nameofthecopiedDB"),QCryptographicHash::Md5).toHex());
QFile file(":/SQLite/nameofsourceDB.sqlite");
file.copy("./Databases/" + new_name + ".sqlite");
file.close();
Since I have the DB I would to use in my project in SQLite folder from my resources (:, indicates resources).
And then, in QML file, the openDatabaseSync() function:
basedades = Sql.LocalStorage.openDatabaseSync('nameofthecopiedDB',"1.0","Els meus entrenaments",1000000,"QSQLITE")
Thank you!
openDatabaseSync searches or creates dbs in the directory used for storing offline data.
That directory is identified by the data member offlineStoragePath of the QQmlEngine class.
To change it, you can use the the member method setOfflineStoragePath (see here for further details).
The first argument for openDatabaseSync is:
The name of the database passed to openDatabase()
See here for further details.
I'm experimenting a weird issue detecting if a file exists or not.
I'm working with SQLite, so I have a DB file in my App, which is Member of my Project in Target Membership, it's only the DB structure.
In my AppDelegate I'm checking if the file exists:
let fm = NSFileManager.defaultManager()
var docDir = ""
docDir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let dbName:String = String.fromCString("db22.sqlite3")!
let path = docDir.stringByAppendingPathComponent(dbName)
In that point the file is created (not the idea), when I print the path, the file exist with size 0.
println("Database path: \(path)")
-rw-r--r-- 1 LLL staff 0 Jan 24 22:49 /Users/LLL/Library/Developer/CoreSimulator/Devices/F18F613D-B032-4B0A-87FC-3E484FC0C024/data/Containers/Data/Application/74FE784B-F131-4C60-9846-21D115E08594/Documents/db22.sqlite3
Just before run the app:
$ find /Users/LLL/Library/Developer/ -name db22.sqlite3
Nothing there.
So my next if in order to check if the file exists or not, is always returning TRUE:
if !(fm.fileExistsAtPath(path)) {
...
...
fm.copyItemAtPath(from, toPath: path, error: &error)
...
...
I tried with Reset Content and Settings in the Simulator, and also closing the project and deleting the all the files and directories in Library/Developer//Xcode/DerivedData/
But the results are the same (Product -> Clean also in XCode).
I was using this file before, working just fine, copying it to my DocumentDirectory in order to modify my DB, I deleted because I changed something in the tables, and suddenly was not working anymore.
If I tried changing the name dbName variable to something that I've never used before, then the file is not created, and the fileExistsAtPath is returning FALSE, as it should be doing also with the previous one.
I also deleted the db22.sqlite3 from my XCode Project, I cleaned and Cleared all the settings, deleting all the files in DerivedData...but the same result.
Any ideas?
Thanks in advance guys!
In this blog post, some prerequisite code for getting started using SQLite in Windows Store Apps is given, for adding to the OnLaunched method of App.xaml.cs:
// Get a reference to the SQLite database
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "customers.sqlite");
My question is: Can I use any arbitrary value to replace the "customers.sqlite" part, or does it have to match something else in my code, such as the name of my table definition class (in my case "PhotraxCoreData.cs" which, according to Mr. Green's suggestion, I added below a newly-created "Models" folder)?
My understanding is that, once I've got those classes defined (I do), and the code above in App.xaml.cs, along with this there (adapted for my SQLite classes):
using (var db = new SQLite.SQLiteConnection(this.DBPath))
{
// Create the tables if they don't exist
db.CreateTable<PhotraxBaseData>();
db.CreateTable<PhotraxNames>();
db.CreateTable<PhotraxQueries>();
}
...SQLite tables based on those classes I specified will be created, and have the name "customers.sqlite" (provided I don't change it).
So, can I use:
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "platypus.sqlite");
...or must it be something like:
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "PhotraxCoreData.sqlite");
That database name is just a file name.
The directory must be accessible by your app, but the file name can be anything.
AS CL says, the file name can be anything the app has direct access to. Windows Store apps have limited access to the file system, so the sqlite database must be in either the apps install location (read only) or it's app data folder (read write). A common pattern is to ship a seed database in the app package and then copy it from the install location to app data on first use so it can be written to.
I'm developing an ASP.NET webapp that has a multilanguage feature allowing the webmaster to create new languages at runtime.
The approach that I was thinking is the following:
The user selects one available (not created) language.
When the user confirms, the application automatically copies a set of existing resources, replacing the filename with the new culture. For example: default.aspx.en-us.resx to default.aspx.es-ar.resx.
The user edits the recently created resources.
Currently I'm having troubles with step number 2. I've achieved to copy the resources, but then these new resources are ignored. I think that this happens because the new resources are not included in the running assembly, and therefore are being ignored.
When I test the following code in my local project, I would have to manually add the new resources to the solution and then recompile to make it work.
Does anyone know how to make this work?
This is the code of the mentioned copy.
string _dir = path_ + "App_LocalResources\\\\";
DirectoryInfo _dirInfo = new DirectoryInfo(_dir);
foreach (FileInfo _file in _dirInfo.GetFiles("*en-us.resx")) {
_file.CopyTo(_dir + _file.Name.Replace("en-us", idioma_.Cultura));
}
string _dir2 = path_ + "App_GlobalResources\\\\";
_dirInfo = new DirectoryInfo(_dir2);
foreach (FileInfo _file in _dirInfo.GetFiles("*en-us.resx")) {
_file.CopyTo(_dir2 + _file.Name.Replace("en-us", idioma_.Cultura));
}
Thank you very much.
Creating or editing Resource files is not possible the same way as reading data.
In order to create or edit a resource file, you should do it the same way you create or edit XML files because resource files have with a specific structured XML elements.
Maybe this article will help you...