diff options
| author | Mark Newnham <mark@newnhams.com> | 2016-04-14 17:26:50 -0600 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2016-04-27 19:46:25 +0200 |
| commit | 1212f9d410a63977246f00bbec68f33b2ff05e74 (patch) | |
| tree | 4e928c456970824d3773854ccaeeed014639b6fd /drivers | |
| parent | a4c04ed9002842ce430ccff9bc9bcc402524da32 (diff) | |
| download | adodb-1212f9d410a63977246f00bbec68f33b2ff05e74.tar.gz adodb-1212f9d410a63977246f00bbec68f33b2ff05e74.tar.bz2 adodb-1212f9d410a63977246f00bbec68f33b2ff05e74.zip | |
New helper methods: day(), month(), year()
These new methods provide a simple shortcut to a timestamp field
formatted with the following values:
- Day as zero padded 2 digit number
- Month as zero padded 2 digit number
- Year as 4 digit number
The methods are documented in the ADOdb reference manual.
The sqlite version of these methods avoids the DST issue with sqlDate() by
directly calling the native date functions instead of adodb_date().
Fixes #225
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/adodb-sqlite.inc.php | 35 | ||||
| -rw-r--r-- | drivers/adodb-sqlite3.inc.php | 57 |
2 files changed, 91 insertions, 1 deletions
diff --git a/drivers/adodb-sqlite.inc.php b/drivers/adodb-sqlite.inc.php index 12604a1f..390df10f 100644 --- a/drivers/adodb-sqlite.inc.php +++ b/drivers/adodb-sqlite.inc.php @@ -371,6 +371,41 @@ class ADODB_sqlite extends ADOConnection { return ADODB_STRINGMAX_NOLIMIT; } + /* + * Converts a date to a month only field and pads it to 2 characters + * + * @param str $fld The name of the field to process + * @return str The SQL Statement + */ + function month($fld) + { + $x = "strftime('%m',$fld)"; + + return $x; + } + + /* + * Converts a date to a day only field and pads it to 2 characters + * + * @param str $fld The name of the field to process + * @return str The SQL Statement + */ + function day($fld) { + $x = "strftime('%d',$fld)"; + return $x; + } + + /* + * Converts a date to a year only field + * + * @param str $fld The name of the field to process + * @return str The SQL Statement + */ + function year($fld) { + $x = "strftime('%Y',$fld)"; + + return $x; + } } /*-------------------------------------------------------------------------------------- diff --git a/drivers/adodb-sqlite3.inc.php b/drivers/adodb-sqlite3.inc.php index 0655b7a7..9c5ae36b 100644 --- a/drivers/adodb-sqlite3.inc.php +++ b/drivers/adodb-sqlite3.inc.php @@ -277,11 +277,22 @@ class ADODB_sqlite3 extends ADOConnection { function SQLDate($fmt, $col=false) { + /* + * In order to map the values correctly, we must ensure the proper + * casing for certain fields + * Y must be UC, because y is a 2 digit year + * d must be LC, because D is 3 char day + * A must be UC because a is non-portable am + * Q must be UC because q means nothing + */ + $fromChars = array('y','D','a','q'); + $toChars = array('Y','d','A','Q'); + $fmt = str_replace($fromChars,$toChars,$fmt); + $fmt = $this->qstr($fmt); return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)"; } - function _createFunctions() { $this->_connectionID->createFunction('adodb_date', 'adodb_date', 1); @@ -475,6 +486,50 @@ class ADODB_sqlite3 extends ADOConnection { return ADODB_STRINGMAX_NOLIMIT; } + /** + * Converts a date to a month only field and pads it to 2 characters + * + * This uses the more efficient strftime native function to process + * + * @param str $fld The name of the field to process + * + * @return str The SQL Statement + */ + function month($fld) + { + $x = "strftime('%m',$fld)"; + return $x; + } + + /** + * Converts a date to a day only field and pads it to 2 characters + * + * This uses the more efficient strftime native function to process + * + * @param str $fld The name of the field to process + * + * @return str The SQL Statement + */ + function day($fld) { + $x = "strftime('%d',$fld)"; + return $x; + } + + /** + * Converts a date to a year only field + * + * This uses the more efficient strftime native function to process + * + * @param str $fld The name of the field to process + * + * @return str The SQL Statement + */ + function year($fld) + { + $x = "strftime('%Y',$fld)"; + return $x; + } + } /*-------------------------------------------------------------------------------------- |
