I developing an application using ionic1 and AngularJS.When i want to go back to previous view i must save some data into sqlite database using sqlite plugin from https://github.com/litehelpers/Cordova-sqlite-storage.git.When i press button to go back i see a lag when it pass from a view to another.The sqlite table structure have two columns:
->Id -primary key -integer
->data-string
In this table i want to save data field as string(from json).
Does anyone knows how to make this process faster? I'm using an iPad for testing.
I'm posting my code here to show how save function is implemented.Thanks for any help. :)
$scope.storeProfileDataCourses = function(data) {
console.log('insertData');
var querySelect = "SELECT * FROM Table where Id=?";
$cordovaSQLite.execute(db, querySelect, [crewId]).then(function(res) {
console.log('Rows:' + res.rows.length);
if (res.rows.length > 0) {
var queryUpdate = "UPDATE Table SET data=? WHERE Id=?";
$cordovaSQLite.execute(db, queryUpdate, [JSON.stringify(data), crewId]).then(function(res) {
console.log('update');
console.log(res);
}, function(err) {
console.error(err);
});
} else {
console.log('Need to insert');
var query = "INSERT INTO Table(Id,data) VALUES (?,?)";
$cordovaSQLite.execute(db, query, [Id, JSON.stringify(data)]).then(function(res) {
console.log("INSERT ID -> " + res.insertId);
}, function(err) {
console.error(err);
});
}
});
}
Related
I have data in firebase database and the data is structured as shown in the attached image. I am trying to search using search bar to look for the name of recipe(s) when user enter search query in the app. Indexing rules currently set also shown in the attached image. Here is my code:
self.findRecipes(text: "Lemon")
func findRecipes(text: String)->Void{
ref.child("Categories").queryOrdered(byChild: "recipeName").queryStarting(atValue: text).queryEnding(atValue: text+"\u{f8ff}").observe(.value, with: { snapshot in
print(snapshot)
})
}
The output in the console is
Snap (Categories) <null>
Any help?
Sorry, I only know how to retrieve data successfully using search bar from firestore DB in webapps. May be it can help you.
HTML:
<input type="text" placeholder="search" id="latestHotDogStatus">
<ul id="pastComments2"></ul>
<li><id="loadButton">Search</li>
JS:
firebase.initializeApp(config);
var firestore = firebase.firestore();
var docRef = firestore.collection("indian");
var showat2 = document.querySelector("#pastComments2");
var loadbutton = document.querySelector("#loadButton");
var inputTextField = document.querySelector("#latestHotDogStatus");
loadbutton.addEventListener("click",function(){
docRef.get()
.then(snapshot => {
snapshot.forEach(doc => {
const myData = doc.data();
if(myData.dname == inputTextField.value){
showat2.innerHTML += myData.dname+" "+myData.dno+myData.no+ ;
inputTextField.innerHTML = " ";
}
});
}).catch(function(error){
console.log("error: "+error);
});
});
My TFS hub extension (on-premise 2015.3) does not load correctly because of unexpected extension data service behaviour and not getting its needed preferences. The extension users store - after installation once during first-start/loading the hub page - extension preferences on the collection-level, as key-value pairs (getValue/setValue from extension data service API), and if the hub page gets reloaded the preferences are stored already. It's like an Application Wizard/First start Dialog in my hub page.
But when I install the extension on another collection of the same TFS and want to store (=setValue) preferences for that collection it comes back with OK (can see it in F12->network capture of Internet Explorer), but cannot find these previously entered/stored key-value pairs when refreshing (=getValue on the key) my hub. It delivers an empty value for the key, and the "first-start" dialog reappears again, what shouldnt happen if there was a value for the key. Already debugged, it always comes back empty (empty value) in that collection. No error from the service, nothing to capture, nothing to debug.
Can I check somewhere else (on the TFS logs, event viewer, or database) for deeper debugging?
I also tried with Powershell and restcalls manually by putting and getting the json on the Rest urls for the extension data service. In one collection it works (manually and per hub extension) but for the other collection the data service does not work.
Is there a known issue in 2015.3 in the extension data service? I really have a problem if I cannot store the preferences of the extension anywhere - storing it to an default source control path would be an alternative, but I do not want to force the projects to check-in preferences for my extension...
EDIT:
Adding relevant code snippet
function showSourceControlDialog(project: string/*TFS_Core_Contracts.TeamProjectReference*/) {
return Q.Promise(function (resolve, reject) {
//setTimeout(function () {
var thatProjectIDclean = project/*.id*/.replace(/-/g, "_");
var enterSourceControlPathDialog = VSS_Controls_Dialogs.show(VSS_Controls_Dialogs.ModalDialog, {
title: "Please now enter source control path for " + thisProjectName /*project.name*/,
content: $("<p/>").addClass("confirmation-text").html("<label><b>Source Control Path</b> to preferences file, e.g. '$/" + thisProjectName /*thisCollectionName + "/" + project.name*/ + "/.../...xml:</label><input id='enterSourceControlPathInput' size='40'/>" /*+ projectName + ".xml"*/),
useBowtieStyle: true,
buttons: {
"Cancel": function () {
enterSourceControlPathDialog.close();
enterSourceControlPathDialog.dispose();
reject("cancelled");
},
"OK": function () {
sourceControlPath = $("input#enterSourceControlPathInput").val();
if (sourceControlPath) {
setConfiguration(thatProjectIDclean, sourceControlPath).then(function (setToThisPath) {
console.log(setToThisPath);
enterSourceControlPathDialog.close();
enterSourceControlPathDialog.dispose();
$(".bss-button").show();
$(".bss-tvc").show();
resolve(sourceControlPath);
}).catch(function (error) {
reject(error);
})
}
}
}
});
//}, 10000);
});
}
function setConfiguration(key: string, value: string) {
return Q.Promise(function (resolve, reject) {
// Get data service
VSS.getService(VSS.ServiceIds.ExtensionData).then(function (dataService: IExtensionDataService) {
// Set value in collection scope
dataService.setValue(pssVersion + "_" + key, value/*, { scopeType: "Project Collection" }*/).then(function (setToThis: string) {
console.log(pssVersion + "_" + key + " is now " + setToThis );
resolve(setToThis);
}, function (error) {
reject(error);
console.log(error);
}, function (error) {
reject(error);
console.log(error);
});
});
}
function getConfiguration(key: string) {
return Q.Promise(function (resolve, reject) {
// Get data service
VSS.getService(VSS.ServiceIds.ExtensionData).then(function (dataService: IExtensionDataService) {
// Get value in collection scope
dataService.getValue(pssVersion + "_" + key/*, { scopeType: "Project Collection" }*/).then(function (gotThis: string) {
sourceControlPath = gotThis;
console.log(pssVersion + "_" + key + " is " + gotThis );
resolve(gotThis);
}, function (error) {
reject(error);
console.log(error);
});
}, function (error) {
reject(error);
console.log(error);
});
});
}
try {
console.log(thisProjectIDclean);
getConfiguration(thisProjectIDclean).then(function (resultPath: string) {
console.log(resultPath);
console.log(sourceControlPath);
if (!resultPath) {
//getProjects().then(function (resultProjects: TFS_Core_Contracts.TeamProjectReference[]) {
// resultProjects.forEach(function (resultProject: TFS_Core_Contracts.TeamProjectReference) {
showSourceControlDialog(thisProjectID/*resultProject*/).then(function () {
getXMLTree();
}, function (error) {
console.log(error);
});
// }, function (error) {
// console.log(error);
// });
//}, function (error) {
// console.log(error);
//});
} else {
getXMLTree();
}
});
} catch (error) {
console.log(error);
}
Unfortunately what you are trying to do is not possible. Referring to the example the "maximum" scope you can store extension data in is the "Project Collection".
From my experience while fiddling with ExtensionDataService it is not possible to query data from a "foreign" collection.
I have a marketplace web app, where users can upload items, and of course they can also see images associated with these items. The problem is organizing the storage buckets, I was thinking to make the path itemImages/itemUID/image1.jpg. The problem is getting the itemUID, which is automatically generated, after an item is added to the database.
Here's a code snippet I have for adding items to the db:
itemsRef.push({
title: title,
description: description,
tags: tags,
price: price,
});
and here's a simplified function I use to store an image:
var uploadTask = imageNewItemRef.child('fakeUID' + '/' + imageNames[x]).putString(images[x], 'base64');
uploadTask.on('state_changed', function(snapshot) {
}, function(error) {
console.log("error uploading image");
}, function() {
var downloadURL = uploadTask.snapshot.downloadURL;
console.log(downloadURL);
});
as you can see, I'm using a hardcoded fakeUID link for testing purposes, but I have no clue (and searching hasn't helped), on how to have a uniqueUID instead of a fake one, that is linked to the item :/
Any help is appreciated!
Apologies for poorly written (and untested) JS, but would something like this work?
// create a new push ID and update the DB with some information
var currentItemRef = itemsRef.push({
title: title,
description: description,
tags: tags,
price: price,
}).then(function() {
var storageRef = firebase.storage().ref();
// currentItemRef.name is the unique key from the DB
return storageRef.child(currentItemRef.name + '/' + imageNames[x]).putString(images[x], 'base64');
}).then(function(snapshot) {
// update the DB with the download URL
return currentItemRef.update({
url: snapshot.metadata.downloadURLs[0]
});
}).catch(function(error) {
console.error(error);
});
So am experimenting with Webix and so far I like it. Am playing around with the mobile calendar/scheduler and am getting stuck with saving new events into mysql database. I have followed the tutorials and docs about saving data to the database and indeed I am able to save new events. Problem is that it is saving the new events twice, and I have failed to figure out why. Here is the code:
webix.ready(function(){
webix.ui.fullScreen();
webix.ui({
rows:[
{
view: "toolbar", id:"toolbar", elements:[
{
view: "icon", icon: "bars",
click: function(){
if( $$("menu").config.hidden){
$$("menu").show();
}
else
$$("menu").hide();
}
},
{
view: "label",
label: "JPlan"
}
]
},
{
view: "scheduler",
id: "scheduler",
url: "data/getEvents.php",
save:{
"insert":"data/saveEvents.php",
"update":"data/update.php",
"delete":"data/delete.php"
}
}
]
});
});
And the php code to save the new events:
<?php
include('mysql.class.php');
$db = new MySQL();
$values = array();
$now = time();
$values["eventTitle"] = MySQL::SQLValue($_POST['text']);
$values["eventJudge"] = MySQL::SQLValue($_POST['judge']);
$values["eventStart"] = MySQL::SQLValue($_POST['start_date']);
$values["eventEnd"] = MySQL::SQLValue($_POST['end_date']);
$values["eventNotes"] = MySQL::SQLValue($_POST['details']);
$values["eventAddedTime"] = MySQL::SQLValue($now);
$values["eventAddedBy"] = MySQL::SQLValue('');
// Execute the insert
$result = $db->InsertRow("tbl_events", $values);
?>
The app loads all events from the database well. It is just that when I save a new event, it saves the evet twice in the database. I have not yet worked on the update and delete code.
Any help?
Client side code expects some valid JSON response from a server-side, as confirmation that the save operation was successful. Otherwise, a client-side code may make another attempt to save a data.
$result = $db->InsertRow("tbl_events", $values);
$id = get_id_of_new_record();
echo "{ id: $id }";
I am trying to use Node CSV Parser to read in a query result from my Mongo database and write it out to a csv file.
When I run my script, I get a csv file with two [object] entries on the first line and everything else blank.
This is my code:
// node samples/sample.js
var csv = require('csv');
var mongoose = require('mongoose');
var User = require('../models/userModel').User;
dsn = "mongodb://localhost/test";
mongoose.connect(dsn);
console.log ("here");
var users = User.find({}, function(err, result){
console.log(result);
});
var columns = ['userName','agencyName','email','password','id'];
csv()
.from(users, {
columns: true
})
.toPath(__dirname+'/users.csv',{
columns: ['userName','agencyName','email','password','id']
})
.transform(function(data){
data.unshift(data.pop());
return data;
})
.on('data',function(data,index){
console.log('#'+index+' '+JSON.stringify(data));
})
.on('end',function(count){
console.log('Number of lines: '+count);
})
.on('error',function(error){
console.log(error.message);
});
This is the data displayed in terminal:
[ { userName: 'LasVegas',
agencyName: 'City of Las Vegas',
email: 'lasvegas#gmail.com',
password: 'upload1',
_id: 4ffe2e6bddc0c02b15000001 } ]
I have only entered one user into the database so I believe it is correct.
Any help would be greatly appreciated!
EDIT:
Here is my code after trying to call csv in the callback:
// node samples/sample.js
var csv = require('csv');
var mongoose = require('mongoose');
var User = require('../models/userModel').User;
dsn = "mongodb://localhost/test";
mongoose.connect(dsn);
console.log ("here");
var columns = ['userName','agencyName','email','password','id'];
var users = User.find({}, function(err, result){
console.log(result);
if (err){
callback(err,null);
}else{
csv()
.from(users, {
columns: true
})
.toPath(__dirname+'/users.csv',{
columns: ['userName','agencyName','email','password','id']
})
.transform(function(data){
data.unshift(data.pop());
return data;
})
.on('data',function(data,index){
console.log('#'+index+' '+JSON.stringify(data));
})
.on('end',function(count){
console.log('Number of lines: '+count);
})
.on('error',function(error){
console.log(error.message);
})
}
});
Now instead of two [object] fields, the fields contain weird symbols and I am asked to choose a filter when opening the file.
Your call to User.find() is asynchronous; it's not assigning the results of the search to users. You need to move your call to csv into the callback and either replace the reference to users there with results or rename the callback parameter to users.