Mark M. | has entered the room |
Jun 30 | 3:55 PM |
Mark M. | turned on guest access |
Jun 30 | 4:00 PM |
Gabriel C. | has entered the room |
Mark M. |
hello, Gabriel
|
Mark M. |
how can I help you today"
|
Mark M. |
er, today?
|
Gabriel C. |
Hello Mark
|
Gabriel C. |
Well i've just begun to program, so i am very new to all this
|
Gabriel C. |
so i just wanted to make sure you knew that. Albeit im new, i still have a specific objective
|
Gabriel C. |
So right now my problem is how i would go about storing data on my app
|
Gabriel C. |
I've looked at all the available databases on the Android Developers website but I still can't seem to pin point the right one
|
Mark M. |
I am not quite certain what you mean by "all the available databases on the Android Developers" Web site
|
Mark M. |
usually, if an app is going to use a database, it creates its own
|
Gabriel C. |
I mean i looked at Shared Preferences, SQLite
|
Jun 30 | 4:05 PM |
Mark M. |
ah, OK
|
Gabriel C. |
so If i had multiple Strings, like say a thousand, and each of these Strings held about a paragraph of words
|
Gabriel C. |
and I wanted to create a kind of retrieval system in my code where the user would answer a few questions and based on their choices they would get one of those specific strings
|
Gabriel C. |
Which database or data storage system should i use?
|
Mark M. |
off the cuff, that feels like SQLite
|
Mark M. |
it definitely is not SharedPreferences
|
Mark M. |
you could create your own files outside of a database if you prefer
|
Gabriel C. |
Would they still be imported onto the app and the user wouldn't have to have internet to access them?
|
Mark M. |
that's a separate issue
|
Mark M. |
where are these strings coming from?
|
Mark M. |
(along with the other data associated with them for your retrieval system)
|
Gabriel C. |
I'll be writing all of them pretty much
|
Mark M. |
yes, but you don't live on everyone's phones :-)
|
Mark M. |
(at least, I hope not)
|
Mark M. |
are you saying that you are intending to ship the strings with the app?
|
Gabriel C. |
touche. Yeah, i was hoping that was a thing
|
Mark M. |
well, there are various ways of shipping data with an app
|
Mark M. |
and various ways of retrieving data within an app
|
Jun 30 | 4:10 PM |
Mark M. |
and they are not necessarily closely tied together
|
Gabriel C. |
that works. Well basically what I wanted to make was a quote generator type thing
|
Mark M. |
for example, you could package the strings in a SQLite database on your development machine
|
Mark M. |
then package that database with the app, using SQLiteAssetHelper
|
Mark M. |
I have a section on SQLiteAssetHelper in the book
|
Mark M. | |
Gabriel C. |
Sweet, thank you. I'll study that.
|
Gabriel C. |
So for the database though, doesn't it have to be structured a specific way in order for it to be retrieved properly
|
Mark M. |
well, SQLite is a relational database
|
Mark M. |
rows and columns
|
Gabriel C. |
That could work
|
Mark M. |
my assumption is that you would have various columns that would tie into your decision-making criteria for which strings are relevant (e.g., category)
|
Mark M. |
in addition to a column for the string itself
|
Gabriel C. |
yeah!
|
Mark M. |
SQLite also supports full-text searching, if you wanted to do keyword searches within the strings
|
Mark M. |
the APK edition of my book, for example, uses SQLite full-text search for its search support
|
Jun 30 | 4:15 PM |
Gabriel C. |
thats dope. So for the retrieval system/set up in the code if i wanted them to chose a topic (actor/actress) and then chose some attributes of the quote (funny, inspiring, spiritual, heartfelt, etc) would i make each one of those a column in SQLite to be retrieved whenever they ask for that type?
|
Mark M. |
that sounds about right
|
Mark M. |
you'd have a topic column and a type column, to associate the values for those attributes with the quote
|
Mark M. |
then run a query to retrieve all quotes matching a user
|
Mark M. |
er, a user's chosen topic and type
|
Gabriel C. |
can I allow them multiple types?
|
Mark M. |
yes, though it makes your database structure more complicated
|
Gabriel C. |
or maybe a hierarchy of types (pick 3, the first is most important)
|
Mark M. |
oh, I see
|
Mark M. |
yes, that too is possible
|
Gabriel C. |
just difficult?
|
Mark M. |
it will probably require some fancy footwork in the SQL or else some post-processing of the query results in Java
|
Jun 30 | 4:20 PM |
Gabriel C. |
So would it make it simpler to have all the Strings in the SQL, have them choose the topic to retrieve that set (war-quotes) and then have the cursor kind of sift through to match the specific attributes of what they chose to look for?
|
Mark M. |
more generally, have the SQL query return all rows that could be candidates, and perhaps take advantage of ORDER BY to put them in a deterministic order, then finesse the results further in Java
|
Mark M. |
it may be that what you wind up doing is only getting the actual string when you're done
|
Mark M. |
so you make one query to get attributes of candidates, sift through them in Java to find the One True Quote, then query the database to get the text of the quote
|
Gabriel C. |
That sounds right. could i run you through like table of what i wanted the user to go through and then could you just confirm what you just said was the best way and then point me in the right direction to keep studying and working?
|
Mark M. |
I can try
|
Gabriel C. |
sweet
|
Gabriel C. |
So in the options menu they would have already selected like 3 topics they wanted to come up (actor/actress, spiritual, war-quotes)
|
Jun 30 | 4:25 PM |
Gabriel C. |
after that they would have a list of attributes they want their quote to convey (funny, nice, heart-felt, and all they). They could choose as many as they want but it would try and find the one with the most attributes that they chose (don't have to use all of them)
|
Gabriel C. |
then after that it would search the database and pull one quote for each topic and display it on the screen
|
Mark M. |
by "selected like 3 topics", is "actor/actress" a "topic", or is the name of an actor/actress a "topic"?
|
Gabriel C. |
actor/actress is the topic
|
Gabriel C. |
like the general set, im thinking that would be one of the ways to group all the quotes said by actors and actresses in the SQL
|
Mark M. |
is a quote tied to just one topic? or can a quote have multiple topics?
|
Gabriel C. |
One topic i believe.
|
Gabriel C. |
but it can have the same attributes all across the borad
|
Mark M. |
so, a topic has a 1:N relationship to a quote (one topic has N quotes, one quote has one topic)
|
Gabriel C. |
Yes
|
Mark M. |
and attributes have an M:N relationship to quotes (an attribute has M quotes, a quote has N attributes)
|
Gabriel C. |
Yes
|
Jun 30 | 4:30 PM |
Mark M. |
a classic "normalized" data model for this would have three database tables
|
Mark M. |
one table would be for the quotes
|
Mark M. |
one table would be for the attributes
|
Mark M. |
one table would be for the "join data" tying quotes to attributes
|
Mark M. |
you could argue that there would be a fourth table, for the topics, but if there are no other properties of a topic other than its name, you could skip this
|
Mark M. |
the quotes table would have some sort of unique identifier (such as the SQLite ROWID), the quote itself, the topic for that quote, and any other metadata you want for quotes
|
Mark M. |
the attributes table would have some sort of unique identifier (such as the SQLite ROWID, or the attribute name itself), plus any other metadata you want for attributes
|
Mark M. |
the quotes-attributes join table would have rows tying a quote ID to an attribute ID
|
Mark M. |
you would query the quotes and attributes data to retrieve all the quotes in the selected topics and having at least one of the chosen attributes
|
Mark M. |
and you'd sift through the results in Java
|
Mark M. |
there may be ways of offloading more of the analysis to SQL, but that might get tricky
|
Gabriel C. |
This sounds great
|
Mark M. |
so that you don't load all of the strings (memory-intensive), your initial queries would get the quote IDs, the attributes for each quote, and any other metadata you need
|
Mark M. |
once you chose the quote, you'd go back to the database to retrieve the string
|
Mark M. |
bear in mind that this is a "back of a napkin" analysis of your data model
|
Mark M. |
and so your kilometerage may vary
|
Jun 30 | 4:35 PM |
Gabriel C. |
Its already leagues ahead of where I was.
|
Mark M. |
my book does not go into SQL itself, as there are plenty of educational materials out there for that
|
Gabriel C. |
If need be, could i create another table in the normalized data structure?
|
Mark M. |
in principle, you can do whatever you want
|
Mark M. |
the important part is to come up with the nature of the relationships between different aspects of your data
|
Mark M. |
(the 1:N and M:N stuff from before)
|
Mark M. |
relational databases are then a matter of defining the right tables to represent the data model
|
Gabriel C. |
sweet. So besides SQLite and every keyword and term you placed here, Is there anything else i should study and look out for to create this?
|
Mark M. |
you'll need to find your source of quotes
|
Mark M. |
from a programming standpoint, there are plenty of other things you will wind up worrying about (threads, how to represent this in a UI, etc.)
|
Mark M. |
but a lot of that will be stuff relatively in common with other apps
|
Gabriel C. |
So the "sift through results in Java" you spoke about earlier. Does that involve lot of thread work- like to the SQL and back?
|
Jun 30 | 4:40 PM |
Mark M. |
your database queries themselves need to be on a background thread, as disk I/O is slow
|
Mark M. |
since that work is on a background thread, you may as well do the rest of the analysis on the same background thread, until you come up with the text of the One True Quote
|
Mark M. |
then, the main application thread can display that quote (TextView, WebView, etc.)
|
Gabriel C. |
Sounds like I have a lot more to study, but this has been great man
|
Gabriel C. |
Thank you, very much
|
Mark M. |
you are very welcome
|
Gabriel C. |
Have a great day. And If i wanted to do a private session, is there a way to ask for you personally as you already know most of it?
|
Mark M. |
well, CommonsWare is a one-person firm
|
Mark M. |
so, the chats are all me
|
Gabriel C. |
Oh shit no way. Well thats cool
|
Mark M. |
now, if you mean you want something that is not open to others, that's possible
|
Gabriel C. |
sweet. Ill be back sometime soon mark. thanks again!
|
Mark M. |
note that the chat transcript will be posted to http://commonsware.com/office-hours/ shortly after the chat period ends
|
Gabriel C. |
Thats cool
|
Gabriel C. | has left the room |
Jun 30 | 4:55 PM |
Mark M. | turned off guest access |