let's say i have a SortedCollection called whitepages, each record containing a Customer, with values name and number.
I want to create a function which would write them to a file in such way
name1
number1
name2
number2
I have to admit Im completely stuck here. Could anyone help?
Ok, so I hope you know how to write to file.
And as you noticed that you have sorted collection I suppose that Customers are ordered in the way you want.
Then what you can do is:
(whitepages collect: [ :customer |
customer name,
Character cr asString,
customer number ]) joinUsing: Character cr
This way you'll get a string that you just need to write to the file. Also note that if name or number are not strings you can use asString on them.
The canonical way is to do something like:
whitepages do: [ :customer |
stream
nextPutAll: customer name;
cr;
nextPutAll: customer number;
cr ]
Where stream is a write stream to a file.
Related
I have requirement of having same column names but in case sensitive manner for iOS project.
For Example:
CREATE TABLE TEST ( name TEXT, Name TEXT );
I know that SQLite's columns are case insensitive.
My current approach is using hash function to create unique number for each string.
func hashcode(columnname) -> String { }
I can use this hash code as my column name.
Is there any better approach for this problem?
I have a query that fetches data between 2 dates, using startAt (1 week ago) and endAt (now) on the last_visit fields.
Then I loop through the results to discard users who don’t have a profile picture.
Problem is around 20% of the users have a profile picture, so just to get 100 users with profile pictures, I have to query at least 500 people (I use limitToLast(500)).
Could I make this query more efficient, by somehow specifying something like in SQL: WHERE profile_picture IS NOT NULL?
If possible, I could also use only limitToLast(100) if it was possible to only take the users that do have a profile picture set.
Database looks like:
users: {
{user_uid}: {
profile_picture: null,
last_visit: 123456789
}
{user_uid}: {
profile_picture: 'example.com/pic.png',
last_visit: 123456789
}
}
If you're trying to exclude items that don't have a property, you need to query for the broadest range of values possible.
A simple example would be:
ref.orderByChild('profile_picture').startAt('!').endAt('~')
This will capture most keys that consist of ASCII characters, since ! is the first printable character (#33) and ~ is the last printable character (#126). Be careful with these, because they won't work when your keys consist of unicode characters.
I am using sqlite as my database. It is connected to the livecode project.
The Contacts table has the following data (address and contact number are omitted for security)
ID Name Address Contact No.
1 John ...Philippines 0999999999
2 Kim ...Philippines 0999999999
When I executed this command...
SELECT Name from Contacts ORDER BY ID DESC LIMIT 1
It will return
Kim
In Livecode, I want to store that value to the variable and display it as a Message Box.
How to do that?
You can use any of LiveCodes database functions. First you need to open the database via:
revOpenDatabase("sqlite",filepath[,sqliteOptions])
Then you can query the database via one of the query commands:
revQueryDatabase(databaseID,SQLQuery[,{variablesList | arrayName}])
There is also a function called revDataFromQuery([columnDelim],[rowDelim],databaseID,SQLQuery[,varsList]) that you might use for your query.
Look them up in your dictionary and you may also have a look at the "Book Database" provided via the start center.
So using the last function you can use:
put revOpenDatabase("sqlite","/path/to/your/database") into tDB
revDataFromQuery(,,tDB,"SELECT Name from Contacts ORDER BY ID DESC LIMIT 1", tResult)
answer tResult
(Using empty row and column delimiter as you only select one field in one post.)
So I've got to design a table for clients with fields (Id, name, bla, bla, Phone numbers). The last field terrifies me as there is not only one number, but many. I see 3 ways to accomplish this task
The field is String. Anytime before an insert, the String array of phone numbers is encoded using a delimiter ';' and thereafter inserted as String.
The field is BLOB. The string array is directly stored (no idea if this is possible in sqlite).
Create another table for Phone numbers with field (ClientId, PhoneNumber).
What seems the best approach?
As it is bad practice to store multiple values in one field, the third option stated is the regular way to go.
I have 1M words in my dictionary. Whenever a user issue a query on my website, I will see if the query contains the words in my dictionary and increment the counter corresponding to them individually. Here is the example, say if a user type in "Obama is a president" and "Obama" and "president" are in my dictionary, then I should increment the counter by 1 for "Obama" and "president".
And from time to time, I want to see the top 100 words (most queried words). If I use Hbase to store the counter, what schema should I use? -- I have not come up an efficient one yet.
If I use word in my dictionary as row key, and "counter" as column key, then updating counter(increment) is very efficient. But it's very hard to sort and return the top 100.
Anyone can give a good advice? Thanks.
You can use the natural schema (row key as word and column as count) and use IHBase to get a secondary index on the count column. See https://issues.apache.org/jira/browse/HBASE-2037 for the initial implementation; the current code lives at http://github.com/ykulbak/ihbase.
From Adobe's presentation at HBaseCon 2012 (slide 28 in particular), I suggest using two tables and this sort of data structure for the row key:
name
President => 1000
Test => 900
count
429461296:President => dummyvalue
429461396:Test => dummyvalue
The second table's row keys are derived by using Long.MAX_VALUE - count at that point of time.
As you get new words, just add the "count:word" as a row key to the count table. That way, you always have the top words returned first when you scan the table.
Sorting 1M longs can be done in memory, so what?
Store words x,y,z issued at time t as key:t cols:word:x=1 word:y=1 word:z=1 in a table. Then use a MapRed job to sum up counts for words and get the top 100.
This also enables further analysis.