Migrate SQLite Database from Titanium to Ionic in iOS App - ios

I am updating the app store with an Ionic version of an old Titanium/Alloy app. The Alloy sql.js sync adapter has:
var ALLOY_DB_DEFAULT = "_alloy_";
A backup of a phone running the old app made with iExplorer contains the file:
(App)/Library/Private Documents/_alloy_.sql
Can I access this database like this in Ionic?
db = window.sqlitePlugin.openDatabase({
name: '_alloy_.sql',
location: 1,
})
I am trying to run the old app and test the migration, but Titanium Studio is very difficult to get going at this point. My migration works well if I just stuff the old _alloy_.sql file into the iOS Simulator at:
~/Library/Developer/CoreSimulator/Devices/<id>/data/Containers/Data/Application/<id>/Library/

Old thread response, hopefully someone still finds the answer useful.
We've solved our own bounty.
The database is stored in the IOS Library in the 'Private Data' directory with the filename _alloy_.sql
let tiAppOptions = {name: "Private Documents/_alloy_.sql", iosDatabaseLocation: 'Library'};
this.sqlite.create(tiAppOptions).then((db: SQLiteObject) => {
db.executeSql("SELECT * from table_name", {}).then((data) => {
//do something with the data.
});
}, err => {
console.log(err);
});
Android is stored in the 'default' location with filename _alloy_.sql

Related

How to get the current path of an electron js portable app?

Hello fellow developers/programmers. Today I come to ask for help with something, and is that I'm making an app that if or if it has to be portable, the problem I'm having is that when writing a zip file the app does not find the directories or generates the zip corruptly.
My code that writes the zip file looks like this:
ipcMain.on("report-file", async (event, data) => {
let zipFilePath = "report.zip"
let output = fs.createWriteStream(zipFilePath);
let archive = archiver("zip")
archive.pipe(output);
if (data.saves) {
archive.directory(`game/saves`, false)
archive.directory(`game/cache`, false)
}
archive.append(fs.createReadStream(`log.txt`), {
name: `log.txt`,
})
archive.append(fs.createReadStream(`traceback.txt`), {
name: `traceback.txt`,
})
archive.finalize()
});
Electron Version: 21.2.3
SO: Windows 11
electron-builder Version: 23.6.0
Looking a little more in depth, I found that the app is using the address
C:\User\User\AppData\Local\Temp\[id]\resources\app.asar
and it is trying to compress the files as if they were in that path, however, the files to compress are located where the .exe is. (G:\myapp\dist)
I already tried to fix it by following an old post on the stackoverflow page, however, it didn't solve the problem, so today I decided to ask my question here, do you have any idea how to get the actual path of an electron js portable app?
I found the solution to this, and it was to create a dialog with electron, and load the folder location. Then use resolve together with the address of the executable, this way it loads correctly the address of the folder where the exe is located.
let dir
dir = await dialog.showOpenDialog(win, {
properties: ['openDirectory'],
defaultPath: path.resolve('.', process.env.PORTABLE_EXECUTABLE_DIR)
});

How to Upload Sqlite3 DB in AppData When Install Electron.js App

I am doing one simple Project using Electron, React and SQLite Database.
Everything working fine in locally with my readymade database.
After Build it wouldn't works as expected. I need to upload My database to %Appdata% folder.
Please help me to do this.
To Connect DB I use this.
const path = require('path');
const dbdatapath=path.join(app.getPath('userData'), "db.sqlite3");
const database = new sqlite3.Database(dbdatapath, (err) => {
if (err){ console.log('Database opening error: '+ err);}
else{
console.error('Database Connected sucess ');
}
});
I have some Predefined Master Data to work this App.
I need to upload Database when Install. Or let us know any other way to achieve this?

Ionic 5 capacitor/angular preview files from external url's

I have tried previewanyfile cordova plugin to open files from external url's in Ionic 5 application. It works well with android but on IOS I noticed sometimes it doesnt preview/open PDF files. Just a grey screen with the file name on it. But strangely some PDF files open.
file preview screen
previewProductDocument(url: string) {
const loading = await this.loadingController.create({
message: 'Loading document...',
});
loading.present().then(() => {
this.previewAnyFile.preview(url).then((res) => {
loading.dismiss();
}).catch((err) => {
loading.dismiss();
this.presentToast('Error previewing the document try later', 'danger');
});
});
}
This is the plugin I have used
https://ionicframework.com/docs/native/preview-any-file
capacitor version "#capacitor/core": "^2.2.0",
Noticed this behavior only in IOS simulator + on Real IOS device.
Any idea what is going on here?
Special character (%2F) in the link is the cause of the issue.
For a quick win; either change the link or sanitise before processing.
In this case url.replace('%2F', '/') should work.
However, another link may, probably, contain a different character. Without being 100% sure, it worth a try decodeURI, which is decodeURI(url).

How to download and retrieve local files on iOS with react native and react-native-fetch-blob?

I'm using react-native-fetch-blob to download mp3 files and then playing them later. The problem is that the actual path for RNFetchBlob.fs.dirs.DocumentDir changes when I close the app and restart again, which means I can't use the absolute file path I stored right after downloading the files retrieve the files in the next run of the app.
Here's my code for downloading and storing the file paths:
export function downloadAudio(urlArray) { //download every section in the urlArray
return (dispatch) => {
Promise.all(urlArray.map(section => {
dispatch(startDownload(section.section_id))
console.log('download start for id = ',section.section_id ) //start download
return RNFetchBlob
.config({
path: RNFetchBlob.fs.dirs.DocumentDir + '/courseSections/' + section.section_id + '.mp3',
appendExt: 'mp3'
})
.fetch('GET', section.section_url, {
'Cache-Control': 'no-store'
})
.progress({ count: 10 }, (received, total) => {
console.log(`progress for section ${section.section_id}: `, Math.floor(received/total*100), '%')
dispatch(downloadProgress({id: section.section_id, progress: Math.floor(received/total*100)/100}))
})
.then(res => {
console.log(`section ${section.section_id} is saved to: `, res.path())
return { path: res.path(), id: section.section_id }
})
.then(pathInfo => dispatch(downloadSuccess(pathInfo))) //download finished
}))
.catch((error, statusCode) => {
console.log(statusCode, ' error: ', error)
})
}
}
I stored { path: res.path(), id: section.section_id } as part of persisted app state. But it's not useful cuz next time I open the app, the file path has been reassigned. For example, here's the path one file was downloaded to:
downloaded file path
But after I close the app and restart, the path is changed to:
/Users/NatashaChe/Library/Developer/CoreSimulator/Devices/830778DE-3CE3-4FC7-AA4B-DFBAE999751C/data/Containers/Data/Application/0C47E33F-ACF8-4539-9456-8FF3E8FBECB2/Documents/courseSections/14.mp3
i.e. the files got assigned to a different sub-folder under the Application folder.
Obviously the audio player (I'm using react-native-sound) can't find the file using the original path that the app has stored. So my question is: Is there a way I can fix the path? Or is there some other way of retrieving files that I'm not aware of?
And also, I'm using the iOS simulator on my computer. Haven't tried this on the phone yet. Does anyone know if the above code can be directly used on iphone and have the file saved to my app's directory? Or shall I set the file path in any other way?
I'm using react native 0.41.
I made the following change to make it work, at least on simulator for now. Not sure what'd happen on an actual phone.
When retrieving the file, instead of using the file path as returned by res.path() as in the code above, I now directly use filePath = RNFetchBlob.fs.dirs.DocumentDir + '/courseSections/' + sectionInfo.section.section_id + '.mp3' when retrieving the file.

No Such Table - Cordova and SQLLite

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";

Resources