I am attempting to make a database that stores user information on the device. I am using flutter combined with sqlflite. I want to always store the data of the current user in row one of the SQL database. Is there anyway to do that with the .insert method?
int id = await db.insert(
'user',
user.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
This is the code I am using for inserting, but when the user changes the screen name or email, it will put the user now into the second row.
After a long period of research, I came to discover that the issue was not in my SQL code, it was instead in my use of the code. The object was returning a list of all objects and I was thinking it was returning one object.
Related
I have users table where role is a field in it which can be student, patent, teacher and admin.
I have to insert data in student form in one page, it can be done with users whose role is set to student.
Now in another page there is a form for filling out additional data such as father and mother details.
I used two objects so that I can store this father and mother information.
Now when I click on next button these id's (student_id, father_id, mother_id) should be stored in student_parents table whose fields are student_id, parent_id, relation.
In nutshell there is a student form when I fill this and click on next button I have to enter parent form after filling this form both father_id, mother_id, student_id which comes from Users should be stored in student_patents table.I am new to this.By the way I am using Graphql and Vue.js.
If you could provide us your code sample you would get more accurate answers.
One way is to use APis to POST data to server and then GET them back in another page.
The other solution is to store your data in LocalStorage and then use the stored data in another place.
if you want to save data as objects here is the way :
localStorage stores key-value pairs. So to store a entire javascript object we need to serialize it first (with JSON.stringify, for example):
localStorage.setItem('user', JSON.stringify(user));
Then to retrieve it from the store and convert to an object again:
var user = JSON.parse(localStorage.getItem('user'));
If we need to delete all entries of the store we can simply do:
I insert/update my Realm database like this:
Realm.getDefaultInstance().use {
realmInstance -> realmInstance.executeTransaction {
realm -> realm.insertOrUpdate(data)
}
}
But this puts newly added data at the end of the table content. How can I put the data at the beginning?
Respone from API:
Latest item
Other items
Scenerio A: This is the first time I receive items from API. I insert them in database in the same exact order.
After a while, I've to send the latest item from my local storage. Usually this would be the last item in local database, but as the list is in reverse order from API, I've to send the first item (you can see order of list). Well. After some while I get a new data from API. We insert in database. From this moment, the latest item will be always the last one in database. I could avoid this mess if I just always knew, that the latest item would be the very first item. It would work for both cases.
I need to store an array of ints. Now my issue is, there's an operation that's done quite a few times so I'd like to limit it to one single query. In tha query, I would need to add an int to a certain int from the array.
It's for a timer of the time spent on a certain page. Currently it's just a general counter that counts for all the pages in the same field, so I only have to do
UPDATE user SET active = active+$totaltime WHERE id=:id
with the $totaltime being the time difference between last check and then. Now I'd like to store for certain pages seperately. The problem is I don't know exactly how many pages there will be. I thought about using serialize, but then I'd need to do 2 queries a lot of times which doesn't seem like a good solution.
Are there any other methods to do so?
What you need is a separate table for the levels which keeps track of active time associated with each user on each level.
Lets calls this table userlevels, and give it the following columns:
userid INT
levelid INT
active INT
The primary key should be a combination of the userid and leveid columns, since there can only be one entry for a particular combination of user and level.
Then when you want to update the amount of time a user has spent on a certain level, you would do something like:
INSERT INTO userlevels (userid,levelid,active)
VALUES (:userid,:levelid,$totaltime)
ON DUPLICATE KEY UPDATE active=active+$totaltime;
This creates a new entry in the table if the user has never been on that level before, or adds to the active time if there is already an entry.
This is mysql specific syntax, but the same thing can be achieved on other databases with different calls.
I need to quickly check to see if I have some duplicate values in CoreData. I am doing some background syncing and occasionally a dupe makes it into my system.
I have a ManufacturerID and an ItemID and I cannot have a duplicate value for both, example of bad data:
ManufacturerID ItemID
35 IT001
35 IT001
So I would just want to know if that happened and maybe get a list of those ItemID's, then I need a way to figure out how to get rid of the dupes but this is a good start.
I just need a fast method figure out if they exist or not.
In my app I have a SynchManager that using NSoperations performs synch in background and store new records in the persistent sqlite store only if not alredy stored.
Basically what I do is:
execute a fetch request which retrieves a collections of stored ids (in my case these ids are strings representing urls)
before insert a new object in the store I call a method like "shouldImportObject:", which basically test that the url is not already stored in the database. This is a simplified implementation sample:
for (id objectID in ids) {
if ([objectID isEqual:objectToImport.objectID]) {
return NO;
}
}
return YES;
I am fairly new to Silverlight and RIA services, and I am trying to build a small project to understand it. So basically I created a Business Application, and I have the normal Login screen where I can add a user. That is fine and I can add a user and get him into the aspnet_Users table. Now I have created some extra fields, like Mob No, Tel No, DOB, Locality etc, which I have put in a table I have created called the UserProfile, and my idea is to get the username that was registered, and insert it into my UserProfile table with the other relevant data.
So I created a page called Profile.xaml, I created a UserProfileDomainService.cs where I have just one query, to get the user profile data from the table, and then created a Details DataGrid on my page, and the QueryName in my case is GetUserProfilesQuery(). Now what i wish to do is, get the user logged in, get his username, and check in my table to see if there is already data in the table. If there is populate the fields on the DataGrid with data, so that the user can modify this data, and if not, allow the user to insert data into the table.
So I have created a UserProfileViewModel class, and I want to create the query to get the data relevant to this user. However I got stuck on how to do all this, and how to get the user logged in.
Can anybody give me some advice or point me to some tutorials on how I can achieve this?
Thanks a lot and your help is very much appreciated.
In your domain service query you can use ServiceContext.User.Identity.Name to get the information specific to that user to include in your db query. I do something similar in our project.
We use entity framework so the LINQ to Entities query looks like:
return this.ObjectContext.UserSnapins
.Include("Snapin.EvolutionModule")
.Where(si => si.User.UserName == ServiceContext.User.Identity.Name)
.OrderBy(si => si.PageOrder);