c++builder FDConnection to SQLite after compile the exe - sqlite

I created a Script with c++Builder 11 with Datas stored in a sqlite3 db File.
To Connect to the Sqlite3.db, i used the FireDAC-Connection inside c++builder and all works fine.
In the Connection-Manager (DataExplorer) of C++Builder i set the Path to "D:\TEST.db".
If i share the Compiled Exe to another PC, then its possible there is no Drive D.
I tried in Connection-Manager to use only the Filename "TEST.db" without Path, but ends in a FireDAC Error Message: "FireDAC..Stan..Definition .. not found in []"...
i also tried "#scriptdir & "\TEST.db" in the Connections-Manager.. but dont works, too...
how can i save my TEST.db (sql3-database) in the ScriptDir if the Connection is fix via "FDConnection1" ????
thanks for any help..
Greeting.

You could use the BeforeConnect for pointing your FDConnection Object to the correct database file. In the example below it would point to a database file named "test.db3" which is located in your exe's folder:
void __fastcall TForm4::FDConnection1BeforeConnect(TObject *Sender)
{
dynamic_cast< TFDConnection * >( Sender )->Params->Database =
ExtractFileDir( Application->ExeName ) + "\\test.db3";
}
void __fastcall TForm4::Button1Click(TObject *Sender)
{
FDConnection1->Connected = true;
}
best regards, Herwig

Related

Writing to file in Qt

I have a problem with writing to file, the problem is :
If I write the directory ":/Files/Scores.txt" it won't write anything but it reads from same directory.
But if I used this directory "D:/TicTacToe/TicTacToe/Scores.txt" it writes and reads but i will give the game to my instructor and the path won't be same and the file won't open, any ideas ?!
My write code:
void Write ( QString file)
{
QFile sfile(file);
if(!sfile.open(QFile::ReadOnly |QFile::Text))
{
return;
}
QTextStream in(&sfile);
QString lscores =sfile.readAll() ;
sfile.close();
if(!sfile.open(QFile::WriteOnly |QFile::Text))
{
return;
}
lscores=" "+Xscore+"\t"+" "+Oscore+"\n"+lscores;
QTextStream out(&sfile);
out <<lscores;
sfile.close();
}
Resource files (the ones you put in .qrc file) are read only, as MrEricSir mentioned. If you want to have some configuration/score file with your app you can for example use QApplication::applicationDirPath()
QString settingsFile = QApplication::applicationDirPath() % QLatin1Literal("/scores.txt");
This way you will have always absolute path to the file inside your app directory.
You can also use QDesktopServices::storageLocation with QDesktopServices::DataLocation parameter to obtain data location for your application.

Where is SQLite database stored in Windows phone 8.1

I have a SQLite database in my Windows phone 8.1 application. I am copying it by using this code
public async void UpDatabase()
{
bool isDatabaseExisting = false;
try
{
StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("ComplainSys.db");
isDatabaseExisting = true;
}
catch
{
isDatabaseExisting = false;
}
if (!isDatabaseExisting)
{
StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("ComplainSys.db");
await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
}
}
I want to access that location where it is stored . When I put breakpoint and check that path and try to access that it shown this error.
How do I access that?
ApplicationData.Current.LocalFolder is the folder. But I don't really know how did you try to access the folder using the breakpoint, are you using Windows Explorer to open that folder? The path is local to phone storage, not your computer's one.
I use the other software, i think it's more good than isolated storage and don't need add external classes or same in your project... I used this: http://isostorespy.codeplex.com/downloads/get/835310
Just unzip folder and open your emulator, when emulator is opened, execute .exe and select your emulator, then u can explore local ,roaming and temp folder. Finally this software work with windows phone 8+ (8,8.1). It's too easy!
PD: If u had problems advise me, Good Luck!

can't find IfxBulkCopy in IBM.Data.Informix 2.81.0.0

Q:
My question consists of two parts:
1- I want to use the following class IfxBulkCopy to insert large amount of data but this class doesn't exist in the dll IBM.Data.Informix 2.81.0.0 how to fix this problem.?
Note : the class exist in the IBM.Data.Informix 9.0.0.2 !but i can't use this version because we use an old version of the informix.
When i use the new version i get the following exception :
Invalid argument
StackTrace = " at IBM.Data.Informix.IfxConnection.ReplaceConnectionStringParms(String szValue, IfxConnSettings& connSettings)\r\n at IBM.Data.Informix.IfxConnection.set_ConnectionString(String value)\r\n at Common.DBConnectionForInformix..ctor(String ConnectionStr...
My .cs:
public static void InsertAsBulk(DataTable dt)
{
using (IfxConnection cn = new IfxConnection(ConfigurationManager.ConnectionStrings["aa"].ToString()))
{
cn.Open();
using (IfxBulkCopy copy = new IfxBulkCopy(cn))
{
copy.ColumnMappings.Add(1, 2);
copy.ColumnMappings.Add(2, 3);
copy.ColumnMappings.Add(3, 4);
copy.ColumnMappings.Add(4, 5);
copy.ColumnMappings.Add(5, 6);
copy.ColumnMappings.Add(6, 7);
copy.DestinationTableName = "schday";
copy.WriteToServer(dt);
}
}
}
2- Is the IfxBulkCopy use the transaction concept during the insertion operation or may result inconsistent data also .
Your connection string is fine. Do you have multiple versions of driver installed? I had same problem when I installed OAT, Informix driver and Informix Client SDK on same machine.
This solved my problem:
1. Uninstallation of driver and client sdk + windows restart
2. Installation of Client SDK together with data server driver
3. Checking system PATH variable. I added
C:\Program Files\IBM Informix Client SDK\bin
C:\Program Files\IBM Informix Client SDK\bin\netf20
to system PATH. I'm not sure what was the problem, maybe just changing PATH variable (without unistallation) can fix it.

Flyway output to SQL File

Is it possible to output the db migration to an SQL file instead of directly invoking database changes in flyway?
Most times this will not be needed as with Flyway the DB migrations themselves will already be written in SQL.
Yes it's possible and as far as I am concerned the feature is an absolute must for DBAs who don't want to allow flyway in prod.
I made do with modifying code from here, it's a dry run command for flyway, you can add a filewriter and write out migrationDetails:
https://github.com/killbill/killbill/commit/996a3d5fd096525689dced825eac7a95a8a7817e
I did it like so... Project structure (just copied it out of killbill's project and renamed package to flywaydr:
.
./main
./main/java
./main/java/com
./main/java/com/flywaydr
./main/java/com/flywaydr/CapturingMetaDataTable.java
./main/java/com/flywaydr/CapturingSqlMigrationExecutor.java
./main/java/com/flywaydr/DbMigrateWithDryRun.java
./main/java/com/flywaydr/MigrationInfoCallback.java
./main/java/com/flywaydr/Migrator.java
./main/java/org
./main/java/org/flywaydb
./main/java/org/flywaydb/core
./main/java/org/flywaydb/core/FlywayWithDryRun.java
In Migrator.java add (implement callback and put it in DbMigrateWithDryRun.java) :
} else if ("dryRunMigrate".equals(operation)) {
MigrationInfoCallback mcb = new MigrationInfoCallback();
flyway.dryRunMigrate();
MigrationInfoImpl[] migrationDetails = mcb.getPendingMigrationDetails();
if(migrationDetails.length>0){
writeMasterScriptToFile(migrationDetails);
}
}
Then to write stuff to file something like:
private static void writeMasterScriptToFile(MigrationInfoImpl[] migrationDetails){
FileWriter fw = null;
try{
String masterScriptLoc="path/to/file";
fw = new FileWriter(masterScriptLoc);
LOG.info("Writing output to " + masterScriptLoc);
for (final MigrationInfoImpl migration : migrationDetails){
Path file =Paths.get(migration.getResolvedMigration().getPhysicalLocation());
//if you want to copy actual script files parsed by flyway
Files.copy(file, Paths.get(new StringBuilder(scriptspathloc).append(File.separator).append(file.getFileName().toString()).toString()), REPLACE_EXISTING);
}
//or just get the sql
for (final SqlStatement sqlStatement : sqlStatements) {
//sqlStatement.getSql();
}
fw.write(stuff.toString());
} catch(Exception e){
LOG.error("Could not write to file, io exception was thrown.",e);
} finally{
try{fw.close();}catch(Exception e){LOG.error("Could not close file writer.",e);}
}
}
One last thing to mention, I compile and package this into a jar "with dependencies" (aka fatjar) via maven (google assembly plugin + jar with dependencies) and run it via command like below or you can include it as a dependency and call it via mvn exec:exec goal, which is something I had success with as well.
$ java -jar /path/to/flywaydr-fatjar.jar dryRunMigrate -regular.flyway.configs -etc -etc
I didnt find a way. Switched to mybatis migration. Looks quite nice.

openWithDefaultApplication fails on files in application folder

I'll ONLY recieve an "Error #3000: Illegal path name" if I try to open a file which is placed inside the app-folder of the air. If the file is somewhere else outside of the app-folder it works.
private var file:File = File.documentsDirectory;
public function download():void{
var pdfFilter:FileFilter = new FileFilter("PDF Files", "*.pdf");
file.browseForOpen("Open", [pdfFilter]);
file.addEventListener(Event.SELECT, fileSelected);
}
private function fileSelected(e:Event):void
{
var destination:File = File.applicationDirectory
destination = destination.resolvePath("test.pdf");
/*
//This works, also if the file to copy is placed inside the appfolder
file.copyTo(destination, true);
*/
/*This Throws me an Error #3000, but ONLY if the file is located in
the App folder*/
file.openWithDefaultApplication();
}
When i try to get the same file and copy it to another place it's doing fine.
Why that? Something special to do if i wanna open files which are inside the appfolder?
It also don't work in debug mode - bin-debug.
Regards, Temo
After reading the document a few times i saw that this is not possible (it's not a bug, it's a feature!?!)
Opening files with the default system application
You cannot use the openWithDefaultApplication() method with files located in the application directory.
So I do this instead:
file.copyTo(tempFile);
tempFile.openWithDefaultApplication();
Not so nice, but it works.

Resources