What can I do with pjjTextBase?
With the script you can manage a normalized database system! You can:
- select records from the database on any condition, even very complex
- count records that follow any given condition, even very complex
- sort table as you like (multiple columns, ASC/DESC)
- add, delete, modify records
- create new tables
- append records from other file
- append fields from other file
- find the maximum and minimum values in given field
- find all unique field values
- add and delete fields
- change field names
Normalized, you say?
Yes! You can not only put your data into one big table (which is trivial): you can actually normalize your database, designing a set of linked tables to avoid data redundancy – all these tables will be read into one array with just one line of code.
Let's suppose you have a file books.csv:
id|@author|title|%translation 1|1|Evil Under The Sun|1,2 2|1|A Pocket Full of Rye|1,2,3 3|2|A Study in Scarlet|2,3
and then two another, called author.csv:
id|author 1|Agatha Christie 2|Arthur Conan Doyle 3|Raymond Chandler
and translation.csv:
id|translation 1|French 2|Spanish 3|German
(I'm far from saying that eg. Evil Under The Sun wasn't translated into German; it's just an example, you know.)
All three files should have the same extension.–Mind the @ sign in the header of books.csv, as well as field and file name correspondence: @author, author.csv and author! Exactly the same applies to %translation field.
When books.csv is being connected to, linked file (author.csv) is being read as well, so eg. first record will have following fields:
[id] -> 1 [@author] -> 1 [title] -> Evil Under The Sun [author] -> Agatha Christie [%translation] -> 1,2
Linked table can have own link fields, too. For example you could modify the second table in such a way:
id|author|@country 1|Agatha Christie|1 2|Arthur Conan Doyle|1 3|Raymond Chandler|2
and add another file, called country.csv:
id|country 1|Great Britain 2|USA
so the first record would look as follows:
[id] -> 1 [@author] -> 1 [title] -> Evil Under The Sun [author] -> Agatha Christie [@country] -> 1 [country] -> Great Britain [%translation] -> 1,2
Now, how about %translation field? When books.csv was being connected to, translation.csv was read as well; I just didn't mention this above to explain iteration of connecting via link fields more clearly.
After connecting to all linked files, among them to translation.csv, first record looks this way:
[id] -> 1 [@author] -> 1 [title] -> Evil Under The Sun [author] -> Agatha Christie [@country] -> 1 [country] -> Great Britain [%translation] -> 1,2 [translation] -> Array: [0] -> French [1] -> Spanish
Let me remind that all this has been done with only one line of code:
$books = ptb_connect('books.csv');
Now, isn't it great?–Naturally, if you have databases that are not connected via link or multi field, you need to connect to each of them separately.
To learn more about database theory you may want to read Tore Bostrup's excellent article Introduction to Relational Databases – Part 1: Theoretical Foundation.