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:
- Follow Javadoc documentation style.
- Iterative methods for looping through results.
- Checking of MySQL functions.
- Support for UPDATE and DELETE multiple tables with bindings (does this make sense in the first place?).
- Further implementation of SELECT, CREATE TABLE and ALTER TABLE statements.
- Nested sub-queries.
- SQL Triggers.
Long-term considerations:
- Ports to other languages (having a Java course next term, hmm...)?
- Accomodate other SQLs such as MSSQL or SQLite?
- XML input/output for portability?
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]
-
27th July 2007 [1.0.5]:
Bug fixes for
Drop()andRenameTable(). Updated code forChangeDatabase()toClear()as well. Updated code forDropTable()to doDROP TABLE IF EXISTS.... -
24th July 2007 [1.0.3]:
Added developers documentation.
Bug fixes for
Values(),Set(),OptimizeTable(),DropTable(),RenameTable()andTabulate(). Updated code for specifying foreign keys (i.e. more bug fixes).Truncate()now supports bindings too (missed this out for 1.0.0).ForeignKey()now supportsJoinTo()as well. -
20th July 2007 [1.0.0]:
New
Alias()function to specify aliases for columns. NewJoinTo()function for joining objects binded to tables. Updated constructor andChangeDatabase()functions toCREATE DATABASE...if specified database does not exist and optionally "bind" a MySqueaks object to a particular table. Updated formatted output forINSERTstatements. UpdatedSubmit()function with new parameterSQX_AFFECTED_ROWS. Improved error handling. -
29th June 2007 [0.9.7 beta]:
Minor documentation facelift.
New
XML()function for XML output. NewValues()function forINSERT ... VALUES (...)support. BothLIMITbugs fixed.NULLforSet()bug fixed.Submit()with PHP warning "bug" fixed. Error Exception bug fixed. -
18th June 2007 [0.9.6 beta]:
Added support for
NULLvalues. NewsetError()function. NewChange()function. UpdatedSubmit()parameters. Better error handling. "Split" the original single class into SqueaksCore and MySqueaks, which extends the former. -
12th June 2007 [0.9.3 beta]:
Minor documentation facelift.
Implemented "lazy-style" function names.
Fixed
ALTER TABLE... DROPbug. NewPKI()function. UpdatedSubmit()function. Append backticks forJoin(). -
3rd May 2007 [0.9.0 beta]:
Support for
ALTER TABLE. UpdatedLimits()function. -
23rd April 2007 [0.8.5 beta]:
New
Tabulate()function. UpdatedGetQuery()function. Fixed "CONSTRAINT 1 INDEX..." bug. New values added forJoin()function. -
2nd March 2007 [0.8.3 beta]:
Bug fixes for "ORDER BY" and "GROUP BY without HAVING" bugs.
New
UseEngine(),CreateView(),Union(),CloseView(),CloseUnion(),OptimizeTable(),DropTable()andRenameTable()functions. UpdatedCreateDatabase()andCreateTable()function. - 23rd February 2007 [0.8.1 beta]: Bug fix for missing keys and indexes.
-
19th February 2007 [0.8.0 beta]:
Support for
CONSTRAINT,GROUP BY,HAVING,JOIN,IN,NOT INclauses. NewMatch()function. UpdatedCreateDatabase(),PrimaryKey(),Unique(),ForeignKey()andSelect()functions. -
14th February 2007 [0.7.7 beta]:
Support for
SELECT,UPDATE,INSERT,REPLACE,DELETE,TRUNCATE,CREATE TABLE.
License [menu]
You can read the GNU Public License Version 3 here.