Around here, we like SQL (Structured Query Language) as a tool to work for RDBMS databases (or “data sources”) of all flavours and styles and types and content, and this should come as no surprise, as a lot of thought went into its design. Now SQL commands can, generically speaking, be categorized into …
- DDL (Data definition language) … affecting the structure of the data contained in the “data source”
- DML (Data manipulation language) … affecting the content of the data contained in the “data source”
Notice how open-ended we are about using the term “data source”? That is because SQL is so good, that “data source” can mean lots of different things to lots of different people in lots of different places … even that little room?!
For instance, for this thread of blog postings we want you to think of “data source” equating to “flat file”, and because of how we do things on our www.rjmprogramming.com.au domain Apache/PHP/MySql CentOS (think Linux) Web Server, to be precise here we qualify this to “Linux flat file via PHP“.
We’re going to write our own PHP Flat File Engine where …
- DDL functionality is hidden from view in the logic of the PHP
- DML functionality is available to all users, as vetted by our PHP, whether they realize it or not (“behind the scenes, like, guv'”), as the Engine mechanism that links the user interface to the flat file data stored on our www.rjmprogramming.com.au domain web server in … you guessed it … flat file(s)
What’s the purpose of this? Can’t say for now, because we want to see what genericity happens as we go along here, but we are going to write PHP web applications to use this “Linux flat file Engine via PHP“.
What can’t a flat file data system do that a database (data system) can? We can think of, at the top of our head …
- delimitation issues regarding databases, data tables, data table columns, data table rows … a database handles all this via proprietry database “engine” software … we have to develop our own “flat file” data system thoughts here
- data type “smarts” … we’re keeping it really “everything ends up as a string” … doh … simple, for now, with our flat file data system design
- keys and indexes
- stored procedures
- users, roles, privileges (eg. grant, deny)
- language character sets
- speed (and power) of data manipulation query findings
In our eyes, despite this, this is very much a useful exercise, and am hoping it becomes a practical reality … and you’ll be pleased to know our “prepare the breakfast in the morning before you knew there could be breakfast or know there could be a morning” project is coming along fine, thanks … and thanks for asking … for wide ranging usage applications.
Patently, “delimitation” is the biggest bugbear with our project, but if everything is “funnelled through” our code, and not allowed to escape to other outside usages, we should be able to disallow our inhouse “delimitation” characters, to have it so they are not allowed into the “data content” with a limited annoyance factor to the more adventurous users who wanted to place such characters into their data. And, of course, the other data bit of interest is non-English characters. This will be an evolving matter we think about. You’ll notice when you use database interfacing software, such as PHP and MySql‘s brilliant phpMyAdmin interface, front and centre regarding database design is a language character set of interest. Of course, this is no accident of design, and MySql, and its ilk, are sophisticated and brilliant products that have seen many many many hours of software development time put into them. Please do not think that we are replacing any of this database design and functionality brilliance with our work today, but our work may bring convenience and ease of “getting up and running data source work here on this domain, quickly and easily”.
Okay, thinking DML (Data manipulation language), we want to be able to …
- SELECT [*|Comma separated Column List] FROM [table] WHERE [Where clause] ORDER BY [Comma separated Column List];
- INSERT INTO [table] ([Comma separated Column List]) VALUES ([Comma separated Data List]);
- UPDATE [table] SET [Comma separated list of Column=Data];
- DELETE [table] WHERE [Where clause];
… where the itallicized functionalities may not be in today’s “first draft”.
For us, with our flat file data system, what defines our data content structure are our “delimitation” decisions, as per …
- one database (data source) will be defined via (our) one (big) flat file (with internally controlled naming and path decision system … ie. we control all DDL (Data definition language) internally) record delimited by ` character (to any other database (data source)) … and may throw in an Ascii character 10 (line feed) before its end delimitation, for “internal use only” clarity, and regarding the rule “database names may not contain Ascii character 10 (line feed)”
- one data table will be delimited within the database record as its first column above by | character (ie. in our flat file system design one database has one database table) … which maps to “[table]” above … and may throw in an Ascii character 10 (line feed) before its end delimitation, for “internal use only” clarity, and regarding the rule “database table names may not contain Ascii character 10 (line feed)”
- one data table [Comma separated Column List] will be delimited within the database record as its second column … and may throw in an Ascii character 10 (line feed) before its end delimitation, for “internal use only” clarity, and regarding the rule “column names may not contain Ascii character 10 (line feed)”
- one data table’s third column will be set aside for application specific data, as required … and may throw in an Ascii character 10 (line feed) before its end delimitation, for “internal use only” clarity, and regarding the rule “application specific data may not contain Ascii character 10 (line feed)”
- one data table’s row data source records will be delimited within the database record as its fourth column, delimited from each other by the ~ character, and between “data values” by the Comma character … and may throw in an Ascii character 10 (line feed) after its final “end of all rows” delimitation, for “internal use only” clarity, and regarding the rule “database names may not contain Ascii character 10 (line feed)”
… and by which you can infer …
- we are going to disallow ~ and ` and Comma (ie. “,”) and | from being allowed in “data values” above, period … sorry to all lovers of the Comma character (but we think, later, anyway, we may relent on this restriction … but, for now …)
- for “internal use only, but also for sanity” purposes, at appropriate places we can place Ascii character 10 (line feeds), as we rabbitted on about above
Today’s “Primer Tutorial” job is to take some “flat file system” data, and parse it (ie. via a “passed in” SQL statement).
- If you don’t already have MAMP installed, consider installing MAMP and following steps below … else ignore steps below and click this link to see the equivalent www.rjmprogramming.com.au domain version of what is happening below …
- Take (ie. copy into a buffer) today’s “first draft” flat_file_engine.php and save it to the directory of MAMP equating (most likely) to HTTP://localhost:8888/ (which is /Applications/MAMP/htdocs on this MacBook Pro) with the name flat_file_engine.php
- Take (ie. copy into a buffer) the “flat file system” proposed data …
- Save this data to that same directory of MAMP equating (most likely) to HTTP://localhost:8888/ (which is /Applications/MAMP/htdocs on this MacBook Pro) and call it flat_file.dat
- Make sure MAMP is up and running … then …
- At your favoured web browser’s address bar type (most likely) HTTP://localhost:8888/flat_file_engine.php?sql=SELECT+*+FROM+ourdatatable2
And when you do, do you get the look of the orange part of today’s tutorial picture? We hope so. But early days with functionality here.
As you can see above, the mechanisms to do “flat file data system” work can be very easy to get up and running.
Food for thought, perhaps?
If this was interesting you may be interested in this too.