How to update database file over internet? - objective-c

My App has a database file in its NSBundle. I want to get update database file from internet whenever new database file is available. and this should happen before app displays data from the database file.
Here is the logic i am trying to use. i don't know if it makes sense or is there a better way to do it. an example will be awesome
if (file is available in the Documents Directory)
{
if( check if internet is available )
{
1. get file from network
2. store it in Documents Directory
if ( compare contents of the old & new file)
{
delete downloaded file
} else {
move or delete old file & rename new file ( so that the new file's data can be accessed )
}
} else {
use old file in Documents Directory
}
} else {
copy file from bundle to Documents Directory
}

Ideally you should have a timestamp or version number for the copy of the DB you have on the phone, and transmit that to the server. Then have the server only send a new copy if there is a newer version. Saves the user a lot of data charges.

Related

Restore Embedded RavenDB on top of existing data

I'm trying to do RavenDB backup/restore from within the application. Raven runs in embedded mode. I've got the backups working fine, now I need to do a restore.
Problem with restore that I'd like to restore into the same location that is currently used by embedded storage. My plan was to shut-down embedded storage, delete all the files in the location, restore there:
var configuration = embeddedStore.Configuration;
var backupLocation = // location of a backup folder
var databaseLocation = // location of current DB
// shutdown the storage???
documentStore.Dispose();
// now, trying to delete the directory, I get exception "Can't delete the folder it is in use by other process"
Directory.Delete(databaseLocation, true); // <-- exception here
Directory.CreateDirectory(databaseLocation);
DocumentDatabase.Restore(configuration, backupLocation, databaseLocation, s => { }, defrag: true);
(The full source on GitHub)
The problem with shutting down the storage. From the exception I get, the engine is not shut down, because I can't delete the folder:
The process cannot access the file '_0.cfs' because it is being used by another process.
The application I run is MVC5. Issue that the DB location is set in web.config and I don't really want to modify it in any way, so the restore has got to go in the same location as existing DB.
What is the correct way to restore embedded database into the same location as the existing DB?
one workaround is initialize ravendb(properly in Application_Start) with a condition to not let ravendb start.
if (WebConfigurationManager.AppSettings["RavenDBStartMode"]=="Start")
RavenDB.initialize();
for restoring db change "RavenDBStartMode" to "DontStart" in webconfig so application pool will restart and start your restore operation
string dbLocation = Server.MapPath("your database location");
string backupLocation = Server.MapPath("your backup location");
System.IO.File.Delete(dbLocation);
DocumentDatabase.Restore(new RavenConfiguration() { DataDirectory = dbLocation }
, backupLocation, dbLocation, x => { }, false);
RavenDB.initialize();
finally change your "RavenDBStartMode" to "Start" again so ravendb can start for other restart reasons

Azure: How to synchronize log files without overwriting old ones?

I have an issue about synchronizing a log file to the blob storage. Actually, I can synchronize a log file to the blob storage, but after that when I make a new deployment of my project to the azure my project files are changing and the log files' contents changing too, although the file name stays same. Thus WebRole is trying to synchronize the log file and does it, however because of the file name, file is overwriting and all the data in the blob storage has gone. How can I hold log files for different deployments? I hope I can explain you, sorry for my English.
You can change the fileName before going to use it. By overriding the File property you can add any unique prefix (DeploymentID,TimeTicks,GUID...) to the file name.
public class AzureLocalStorageAppender:RollingFileAppender
{
public override string File
{
get
{
//Trace.WriteLine("get_"+base.File);
return base.File;
}
set
{
base.File = RoleEnvironment.GetLocalResource("LocalResourceNameHere").RootPath + #"\"
+ "_" + Guid.NewGuid().ToString()
+ new FileInfo(value).Name;
//Trace.WriteLine(base.File);
}
}
}

How to open the .db paradox file

i want to view the test.db file, i search for it's editor but didn't get any one
So please help to see the it in editor as like sql server.
i found some sqlite editor but it's not an sqlite file on most forum it say that it is an paradox .db file.
So how do i open it
Thanks
To access Paradox tables in .NET you can use ODBC. Here's a small example (in C#):
private static void RunMinimumParadoxTest()
{
const string ConnectionStringFormat =
"Driver={{Microsoft Paradox Driver (*.db )}};Uid={0};UserCommitSync=Yes;Threads=3;SafeTransactions=0;" +
"ParadoxUserName={0};ParadoxNetStyle=4.x;ParadoxNetPath={1};PageTimeout=5;MaxScanRows=8;" +
"MaxBufferSize=65535;DriverID=538;Fil=Paradox 7.X;DefaultDir={2};Dbq={2};CollatingSequence={3}";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.Odbc");
using (DbConnection connection = factory.CreateConnection())
{
string userName = "Tor";
string paradoxNetPath = #"C:\BdeNet";
string databasePath = #"C:\LangloMainSrv\LData\Ordre\LordWin\Database2011";
string collatingSequence = "Norwegian-Danish";
connection.ConnectionString =
String.Format(ConnectionStringFormat, userName, paradoxNetPath, databasePath, collatingSequence);
connection.Open();
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = "select Count(*) from [OrdreDet] where [Ordrenr] = 81699002";
object itemCount = command.ExecuteScalar();
Console.WriteLine("Order items: {0}", itemCount);
Console.ReadKey();
}
}
}
Also see the following link for more details: http://msdn.microsoft.com/en-us/library/ms710922(VS.85).aspx.
A Paradox db file contains just one flat table. The actual structure of the DB file changed over time and different versions. But you can usually open the DB file with MS Excel - of course that changed over different versions too.
As noted above, other database applications, also including Paradox for Dos and Paradox for Windows, will open the file and other features as well. The key, for example is in the PX file with the same table name.
All of this assumes the table is not password protected, which an application database could be - or that you know the password. Beware if you get an error to that effect.
You can open and view Paradox database files using Database Desktop that is shipped with Borland C++Builder. A free alternative is BB's Database Desktop. The software may require administrator privileges to run correctly.
You can use gnumeric spreadsheet, paradox-db-reader or BB database desktop to read db paradox file.
BB database dekstop able to read XG0 file too.
BB's Database Desktop now called JEDI Database Desktop, but project is closed and it couldn't edit my table. I have had to use some hack: open *.db file in MS Excel 2007, edit it, export to *.csv, close file then Open *.db file in Paradox Data Editor 3.2.0, clear all table data and import previosly saved csv-file. And it works (don't know why but this app can't insert row in my file itself)!

I can't get netbeans to find a txt file I have in the same directory... java.io.FileNotFoundException

I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile around in a few different folders (the src folder, and other random folders in the project's NetBeansProjects folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
Try adding the file to build path ..
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:\MyFiles\Athletics.txt');
hope this helps clear the problem up :)

objective-c open database from a folder

I have an app that contains top level folder with subfolders in the app's package - not the Documents area.
Here's the structure:
Document/
Library/
appPackage
/tmp
The folder is visible when you right-click the and select "show package contents".
The subfolder is in the appPackage and visible at this point. The subfolder in turn contains multiple folders each with database files with same name
appPackage/mainFolder/subFolder_1/app.sql
subFolder_2/app.sql
subFolder_3/app.sql
I'd like to open one of these databases (depending on user's choice). Optimal way would be to open the database from the current location rather than copying it to the Documents area of the app. I am trying to avoid it.
My question is: How do I tell sqlite3 interface to open the database from one of these paths?
BTW, I am able to access a .txt file in these subfolders - but not sure about database.
All help appreciated.
R/- : Sam
NSString *myPath = ...;
sqlite3 *db = NULL;
if (SQLITE_OK == sqlite3_open([myPath fileSystemRepresentation], &db) {
...
}