I'm new with iOS Development and i'm also new with SQLITE database. I used FMDB as a wrapper in my project and i have two tables 1) ParticepentsTable and 2) ExerciseTable.
ParticepentsTable contains 4-Rows like Id, Name, Gender and Exercise_Id and the ExerciseTable contains 2-Rows i.e. Id and exercise_Name.
My questions are as follow:-
1) I want to make a Foreign-key Relation between Table-1 & 2 using FMDB, so that i can store the exercise according to Participants choice.
2) Or any other way to select or insert exercises according to the participants?
3) Can I use Join to fetch data from both the tables according to the Participants id?
Any one can help please!
Tutorial link is more appreciated! Thanks!
By looking at your other question I guess you already sorted this out. Here's my answer anyway. In iOS development it's uncommon to use SQLite directly, instead we use CoreData, which is an API that serializes data to SQLite (or you can configure it to serialize it to binary or XML too).
Here are some links for you:
SQLite
CoreData
Hope this helps!
Related
I'm using .Net 4.5, entity framework 5, database first. I have a junction (many-to-many) table in my database. For this example lets say the table is "StudentsCourses":
Students
-PkStudentId
-Name
Courses
-PkCourseId
-CourseNumber
StudentsCourses
-FkStudentId
-FkCourseId
This works just fine right now. The 'generate model from database' creates a Student entity with a navigation property to the Course entity. But here is where the trouble is:
I need to add another column to the StudentsCourses table. Lets just call this column "CourseYear". So our junction table would now look like this:
StudentsCourses
-FkStudentId
-FkCourseId
-CourseYear
So, I've added this column to the database and ran "Update Model from Database" on the edmx. I would expect to see an entity created for StudentCourses, with a navigation property to both Students and Courses. But no such entity is created. I still see the same two tables (Students & Courses) with the same navigation property as before.
I've done a lot of reading and researching, but haven't really come across a clear-cut answer. There is a wealth of information on code-first which I can't apply to my scenario. Is there a way to get what I'm after? Is it as simple as adding a PkId to the StudentCourses table? SQL Replication is preventing me from doing this. I would think the composite should suffice, but maybe EF needs a PK to do it's magic? I read a little bit about manually setting relationships, but could not find anything speaking to my particular situation. It could be that I am just missing a simple step in the process of updating the edmx from database. I've done this plenty of times when: adding new tables, adding columns, deleting columns, etc. I'm following the same steps as I always do, but maybe I need to do something different in this case?
Thanks ahead of time for any help. It is greatly appreciated. Please let me know if any more information would help.
From what I've gathered it appears as though EF will not generate a model for a table that doesn't have a Primary Key.
I'm a bit late for this, but you have the answer in this thread Updating Entity Framework Model after adding a field to a previous look up only table
As they say here, you have to delete the relationship between Students and Courses in the designer. Then update your model from the database, and make sure StudentsCourses table is checked in the Tables branch of the Add tab.
I am planning to start an iPad app...
In my app there will be 3 UITabels connected to SQLite3. How can i connect all the 3 tables together and control the data in tables with each other?
For Example
IF I have 3 tables
Tabel 1: Name;
Tabel2: Country;
Tabel3: Gender;
The table name displays a large data of different name. suppose if a select a name called Alex . the other name should disappear from the list and in the Country table should list only the country name related to Alex(if there is no Alex in China, then China should not appear). the Gender table should only list Male.
In the same way if i Select USA. the other name Country table should disappear and should list only related names in name list. same thing for Gender table too.
Can any one give me some ideas or Suggestions please.
Any examples or Links are highly appreciated.
While you can implement such behavior manually by using the UITableViewDelegate and UITableViewDataSource protocols, this seems like the perfect example to use CoreData instead of manually building complex models.
CoreData is a technology developed by apple to simplify the creation of apps that rely on such relatively simple data relationships.
http://developer.apple.com/library/ios/#DOCUMENTATION/DataManagement/Conceptual/iPhoneCoreData01/Introduction/Introduction.html
There's nothing like connecting to sqlite.you just have to create a sqlite db ..store your details and access it .If any store action is performed just send a message to classes holding the tableview to update their rows.I assume you are aware of UItableview its delegate methods , datasource etc.
[table reloaddata];
iF TABLES ARE IN SAME VIEWCONTROLLER , YOU ALREADY know that changes have been made and you can reload the tables with by extracting data from sqlite.
To make your job simple and easy yOu can use FMDB as sqlite wrapper.
Sqlite Tutorial
Sqlite Tutorial by Wnderlich
you can use splitebrowser plugin for firefox to see the sqlitedb
I am new to the Zend Framework and this is my first project, I have a list of clubs that when clicked it takes you to a description page of the club you specified. I then want a comments box for this club on the description page. I have a comments table, user table and clubs table in my database, all these tables will have to be linked by a foreign key so that I can see what club the comment is for and which user posted the comment. The problem I am having is understanding which keys will be foreign keys and how to do this in phpmyadmin. Once this is set up I am then wondering how to implement this in the ZendFramework does any one know of any useful materials online that I could read relating to this sort of issue?
Thanks
Rik
Once you set your database use Zend_Db_Adapter to connect to your DB and define classes for each of your tables, extending the abstract class Zend_Db_Table_Abstract as explained here .
I am then wondering how to implement this in the ZendFramework does
any one know of any useful materials online that I could read relating
to this sort of issue
Read this tutorial to get you started with ZF (it has an example similar to what your are trying to do) .
Take a look also at Zend_Db_Select which will help you retrieve data from your database .
and Zend_Db_Table Relationships is also useful.
In a table a foreign key is an "id" that is not the primary key of the table , so if you have 2 tables , clubs and comments , then
in comments table , the foreign key would be the club_id column so you can refer to the club primary key.
You should take the time to learn how a Zend Application is structured , check the documentation on ZendFramework website.
In my web app a user can assign muliple tags to products (like the tagging here on stackoverflow).
There are three tables: products, tags and products_tags to implement a many to many relationship.
My question is, how would you implement this with the Entity Framework (LINQ to SQL):
"Insert only a new tag in the tags table if it doesnt already exist there".
So before the insert i have to check first if a tag exists, whats the best way to accomplish this (best performance) ??
thanks for answers
Simple: The Tag should then be the user assigned key/PK of the entity/table.
If you have troubles synchronizing this with the database, I am sure there's something like (N)Hibernate's merge Method in EntityFramework.
I have a many-to-many relationship between 2 entities in Entity Framework, like here . So, Employees and Projects. At one point, I would like to insert some Projects to a Employees entity in a specific order. By conserving the order I would like to know which was the first preference of the Employees for a Projects entity. The thing is that although I order the Student.Projectslist in the way I like before the insert, when selecting Employees.Projects.FirstOrDefault(), the entities are ordered after the ProjectsId and I don't get the first element I inserted. How can I conserve the order I want?
O course, I could make a new field PreferredProjects and save the other Projects in a random order, since only the preferred one is important for me. But this is not an option, being given the context of the current project's software design.
Thank you in advance...
It sounds like you simply want to have sorted child collection results when you do a query, rather than take full control of the insert order.
You can achieve that using the techniques described in Tip 1 of my tips series.
Hope this helps.
Alex
Program Manager Entity Framework Team.
Unfortunately, there is no easy solution. I have the same problem. The only solution is to save after adding each child item (project). This is the only way to save the order without using a new field column to sort input.
Try Employees.Projects.OrderBy(x => x).FirstOrDefault()