how to make a database?

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
bichlepa
Posts: 148
Joined: 04 Mar 2014 18:29
Location: Germany
Contact:

how to make a database?

Post by bichlepa » 31 Mar 2014 12:55

I'd like to save in a variable a destination and also many locations corresponding to this destination and some timestamps corresponding to the locations. And maybe more.

I need somethink like an ini file. There you have a section, key and value. So my section would be a destination, the key would be a location and the timestamp would be a value.

Does somebody know how to make such data bases?

My current solution is not very good.
How I make this currently: (It's hard to understand :oops: )
I make two lists. One has the name "global_gps_locations_"+{destination} (for example "global_gps_locations_home") and the other "global_gps_locations_times_"+{destination}. When I want to get a corresponding time I firstly search for the index of the location key in "global_gps_locations_"+{destination} and then retrieve the key with the same index in "global_gps_locations_times_"+{destination}.

ZSasha
Posts: 103
Joined: 11 Oct 2013 03:48

Re: how to make a database?

Post by ZSasha » 01 Apr 2014 03:00

seems like a two-dimensional array to me :)
I would like to have arrays implemented but I'm affraid all what we have for now is just a list.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: how to make a database?

Post by Martin » 01 Apr 2014 20:12

Perhaps you could use a map in a script:

Code: Select all

map = newMap();
addMapEntry(map, "key1", "a");
addMapEntry(map, "key2", "b");
addMapEntry(map, "key3", "c");

value = getMapValue(map, "key2");
log(value);// b
At the moment you can only modify maps from a script but there's no editor to edit maps in a graphical user interface (this is on the list but quite low priority since maps are probably not used that often).

@ZSasha: What kind of features of an array are you missing in a list?

ZSasha
Posts: 103
Joined: 11 Oct 2013 03:48

Re: how to make a database?

Post by ZSasha » 01 Apr 2014 20:50

Martin wrote:@ZSasha: What kind of features of an array are you missing in a list?
the main one would be simplicity. the second one - flexibility.
It is much more quicker (both to type and to use) to use an expression like myarray[a] rather than typing what you mentioned above.

For example now I want to make custom-made script to calculate MD5 hash for a (large) file.
I could've opened a file, get a file descriptor and then load the file into a buffer (which is an byte array) piece by piece and do some math using pointers (or array indexes).

Also if you could implement byte arrays and/or pointers - it would be great!

User avatar
bichlepa
Posts: 148
Joined: 04 Mar 2014 18:29
Location: Germany
Contact:

Re: how to make a database?

Post by bichlepa » 02 Apr 2014 07:53

Thanks. A map may be a solution.
But yesterday I found an other convenient solution: A "list" whitch contains many "little_list"s.
In my case one "little_list" contains following entries:
index 0: Location
index 1: Timestamp
index 2: Count. (How often the location was visit.)

Some snipplets:
Add an entry:

Code: Select all

list=addElement(list, newList(location,timestamp,count));
Search for an entry (here for an entry with a certain location):

Code: Select all

i=0;
for (little_list in list)
{
	elem=getElement(little_list, 0);
	if (elem==search_location) index=i;
	i=i+1;
}
//Is there a more performant solution?
Get an entry (Here get the timestamp of the found location):

Code: Select all

timestamp=getElement(getElement(list,1), index);
Replace an entry:

Code: Select all

list=removeElement(list, index);
list=addElement(list, newList(location,timestamp,count));

Post Reply