MySqueaks developers documentation

version: 1.0.5 | dated: 27th July 2007
Written by Han Jun Kwang | Go to MySqueaks web site

Introduction [menu]

You are now reading the developers documentation, which contains more detailed explanations together with coding practices and a list of to-dos. This is targeted at developers who are interested in extending the functionalities of MySqueaks, knowing more about the "hidden" functions of MySqueaks or to fork a project of their own.

CVS is available from Sourceforge. You can browse with your web browser or consult Sourceforge's documentation on getting CVS working for you. If you would like to have write permissions, contact me via SourceForge.

Coding practices [menu]

I've blatantly ignored the "stick to 80 (columns)" rule, but please do try to keep your code to a single line on a typical XGA resolution. That would equate to about 130 to 140 characters per line. Your mileage may vary if you're using larger fonts though. I personally code using Notepad++ at font size 10 but zoomed out by a level, which would probably be around 9 pts. Please use CamelCaps (yes, including the first character, with the exception of setError/getError - my oversight - and toString, which is to placate Java programmers. :D Lastly, please please please *indent* your code properly (using tabs) and as much as possible, use { } brackets for code blocks:

if () {
	// some statements
} else () {
	// more
}

unless it's only a one-liner. I've used a bit of:

if () [single-line statement]
elseif () [single-line statement]
else [single-line statement]

foreach ($array as $current) $temp[] = $current;

So I guess I can excuse you if you do that as well. I'm not particular about comments, but that doesn't mean you can totally forget about them. At least "introduce" what the function is about before the function itself.

Other functions [menu]

This section covers other functions which are not mentioned in the users' documentation.

$sqx->MakeSafe($value [, $no_value_quotes] );

Uses mysql_real_escape_string to prevent SQL injection attacks.

$sqx->Identity($tblname [, $engine [, $char_set [, $collate [, $comment]]]] );

The function for binding the object to an SQL table. As noted, it takes in a similar set of parameters as CreateTable().

$sqx->GetColumnFields($incoming [, $col] );

Loops through the array $incoming and the nested element $col, which defaults to "Field". This is primarily used for the variables $Columns or $JoinColumns. The function returns an empty array if an error occured, which allows for its usage in the in_array() PHP function.

$sqx->CheckField($field [, $check_joins] );

Used for checking valid field names. This requires joined tables to be specified using Join() or Match() first, followed by aliases using Alias(). The function returns an array:

array("query" => $query [, "table" => $table [, "field" => $field]] )

Where $query is a "back-quoted" SQL-safe representation of the field name (with the table name prefix if present), and with either the un-quoted table or field name, or both.

$sqx->DoReset($match);

Simply checks if the object is binded to a table or not, and if so whether the query string $Query starts with $match. Returns true if the second condition fails, i.e. we need to "reset" the query string as does not start with our intended SQL statement.

$sqx->RefreshTables();

Updates the variable $Tables. This is to allow for the inclusion of newly created tables although MySqueaks currently does nothing about tables that have been dropped.

$sqx->PrepareWhere( [$do_extra, [$format]] );
$sqx->PrepareColumns( [$format] );

Two similar functions that basically generates the selection conditions (i.e. WHERE) and column definitions (i.e. for CREATE TABLE and ALTER TABLE) respectively. $do_extra if set to true will perform the ORDER BY and LIMIT clauses as well (which does not apply for certain MySQL statements). $format if set to true adds proper newline breaks and tabs to the SQL query.

$sqx->BuildQuery( [$format] );

The main engine of MySqueaks, enough said.

$sqx->TableFields($tblname [, $get_all] );

Gets the fields of the table specified in $tblname. The function retrieves only the field names by default, setting $get_all to true will return the entire result set from the query SHOW COLUMNS.... The function returns an empty array if an error occured, which allows for its usage in the in_array() PHP function. Note that if $tblname refers to the binded table, the function will simply return $Columns and apply the function GetColumnFields() if required.

$sqx->Tabs($v);

A nifty one-liner function for specifying the number of tabs to "pad" strings. This is used exclusively (as of now) for the XML() function. Note that this function is defined only in the extended MySqueaks class.

To-dos [menu]

Short-term to-dos:

Long-term considerations:

Sample code [menu]

The sample code can be found here. To view the example as an RSS feed, append ?rss=1 to the URL like this.

Download [menu]

Please go to the project page listed on SourceForge.net. Alternatively, should SF.net by down for some peculiar reason, you may also download MySqueaks here.

Changelog [menu]

License [menu]

You can read the GNU Public License Version 3 here.