Does anybody know, that how can I check an inserted record? I would like to create an intro page. When the user visits once, I wanna store it and check it.
$rootScope.insert = function(visited) {
var query = "INSERT INTO shoplist (visited) VALUES (?)";
$cordovaSQLite.execute(db, query, [visited]).then(function(res) {
console.log("INSERT ID -> " + res.insertId);
}, function (err) {
console.error(err);
});
}
$rootScope.insert(1);
Basically I would like to check that visited record is 0 or 1.
What should I do?
You can just write the query
Select from shoplist Where id = ?
Where id is the one your insert returned.
Related
How can I return all the tables stored in my database in the form of a list in Sqlite flutter?
Just query sqlite_master table:
final tables = await database.rawQuery('SELECT * FROM sqlite_master ORDER BY name;');
If you need to get all table names which contain in your database. You can use this method for it. this method return table names list.
//********* Get all tableName from Database *********//
Future<List<String>> getAllTableNames() async {
// you can use your initial name for dbClient
List<Map> maps =
await dbClient.rawQuery('SELECT * FROM sqlite_master ORDER BY name;');
List<String> tableNameList = [];
if (maps.length > 0) {
for (int i = 0; i < maps.length; i++) {
try {
tableNameList.add(maps[i]['name'].toString());
} catch (e) {
print('Exeption : ' + e);
}
}
}`return tableNameList;}
I have a trigger that i have written that I need tested to be able to get code coverage in salesforce:
here is the trigger:
Trigger MyCh_SALESFORCETRIGGERUPDATE_tr_I on Account (after insert)
{
set<ID> ids = Trigger.newMap.keyset();
for(ID id : ids)
{
MyCh_Account__c change = new MyCh_Account__c();
change.Action__c = 'insert';
change.Link__c = id;
change.Processed__c = false;
change.Map__c = 'SALESFORCE TRIGGER UPDATE';
insert change;
}
}
I have tried :
#isTest
public class MyAccountcreationTest
{
static testMethod void testMethod1()
{
Account testAccount = new Account();
testAccount.Name='Test Account' ;
insert testAccount;
Account acc1 = [Select Id, Link__c, Action__c, Processed__c, Map__c from Account where Id =: testAccount.Id];
System.assertEquals(acc1.Name,'Test Account');
System.assertEquals(acc1.Link__c, acc1.Id);
System.assertEquals(acc1.Processed__c,false);
System.assertEquals(acc1.Map__c,'SALESFORCE TRIGGER UPDATE');
System.assertEquals(acc1.Action__c,'insert');
}
}
I expect the test to pass but it gives an error :
Map__c , Action__c , Link__c are not fields of Account object.
Also , how does the test actually link to the trigger itself ?
You are creating a MyCh_Account__c record in your trigger but you're not testing that in your test. You need to query for the record created in your trigger and assert that the fields are correct.
I'm trying to use Firebase and runTransactionBlock to update an Array on a server. I previously was able to add the uid of userToFollow to user's Following node using the solution found on Synchronized Array (for likes/followers) Best Practice [Firebase Swift]. Now I am trying to enable unfollowing by removing the uid of userToFollow from user's Following node, but despite the runTransactionBlock succeeding the data is not getting updated. Here is my code:
static func unfollow(user: FIRUser, userToUnfollow: FIRUser) {
self.database.child("users/"+(user.uid)+"/Following").runTransactionBlock({ (currentData: FIRMutableData!) -> FIRTransactionResult in
var value = currentData?.value as? Array<String>
if (value == nil) {
print("unfollow - user has never followed user ID " + userToUnfollow.uid)
FIRTransactionResult.abort()
} else {
value = value!.filter() {$0 != userToUnfollow.uid}
}
currentData.value = value!
return FIRTransactionResult.successWithValue(currentData)
}) { (error, committed, snapshot) in
if let error = error {
print("unfollow - update user unfollowing transaction, please try again - EXCEPTION: " + error.localizedDescription)
} else {
print("unfollow - update user unfollowing success")
}
}
}
I am trying to update the array by first sorting out the uid of userToUnfollow then syncing this data with Firebase. How can I get this to actually remove the node? Thanks.
I am working on a phonegap application and have the following code:
db = window.openDatabase("AjansDB", "1.0", "Ajans app DB", 2*1024*1024);
//creation
db.transaction(function (tx) {
var sql='CREATE TABLE IF NOT EXISTS USER_DATA (user_id INTEGER PRIMARY KEY, user_name VARCHAR(20))'
tx.executeSql(sql);
});
//insert
var sql="INSERT INTO USER_DATA (user_id,user_name) VALUES (?,?)";
tx.executeSql(sql,[1,"admin"], successCB, errorCB);
Now here is the problem: every time I select from the table I can retrieve the id but not the name ! The id would return "1" while the name would return "undefined"
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM USER_DATA', [], function (tx, results) {
alert(results.rows.item(0).user_name);
});
});
What is going on wrong?
ps: I am not sure if this is gonna make any difference but I am using ionic and angular.js
I was so focused on sql errors that I missed a javascript syntax error. here it's:
var sql='CREATE TABLE IF NOT EXISTS USER_DATA (user_id INTEGER PRIMARY KEY, user_name VARCHAR(20))'
I missed a ";" .. a semicolon.
I have build some dropdown lists using the LINK to Objects method and #html.dropdownlist Webmatrix helper. This works fine.
I want to know how to pass / store the selected value in my database table.
Build of items list in code section
var titlesData = db.Query("SELECT TitleId, Name FROM Titles ORDER BY Name");
titlesListItems = titlesData.Select(i => new SelectListItem {
Value = i.TitleId.ToString(),
Text = i.Name,
Selected = i.TitleId == providerData.TitleId ? true : false
});
HTML markup section:
#Html.DropDownList("titlesCombo","-- Veuillez sélectionner -- ",titlesListItems)
Database update command (see the ???):
db.Execute("UPDATE Providers SET TitleId=#0 WHERE ProviderId=#1",???,providerId)
The method I used for now is to create another variable:
var titleId = "";
if (!IsPost) {
titleId = providerData.TitleId.ToString(); //providerData stores the SQL query result
}
if (IsPost) {
var titleId = Request.Form[TitleID]
db.Execute("UPDATE Providers SET TitleId=#0 WHERE ProviderId=#1",titleId,providerId)
}
Unfortunately, data doesn't get updated
From what I can see, you haven't referenced rightly the DropDownList helper in your code.
Try with the following code:
var titleId = "";
if (!IsPost) {
titleId = providerData.TitleId.ToString();
}
if (IsPost) {
titleId = Request.Form["titlesCombo"];
db.Execute("UPDATE Providers SET TitleId=#0 WHERE ProviderId=#1",titleId,providerId);
}