summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2004-03-18 01:34:58 +0000
committerIlia Alshanetsky <iliaa@php.net>2004-03-18 01:34:58 +0000
commit5442d722c3b36cfc96a8baf82af8891885b7747f (patch)
tree366359a6dd29a9d2214afdc7e7a159f61bd1c480 /ext
parent9b614ccb5ab39ef9e604d811d8ceaaed6e8b1313 (diff)
downloadphp-git-5442d722c3b36cfc96a8baf82af8891885b7747f.tar.gz
Fixed bug #27300 (Improved regex for pg_convert()).
# Patch by benjcarson at digitaljunkies dot ca
Diffstat (limited to 'ext')
-rw-r--r--ext/pgsql/pgsql.c55
1 files changed, 51 insertions, 4 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 2e77c960d1..30916a7bee 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -3998,16 +3998,63 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
ZVAL_STRING(new_val, "NULL", 1);
}
else {
- /* FIXME: better regex must be used */
- if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^[+-]{0,1}[ \\t]+((second|seconds|minute|minute|hour|hour|day|days|week|weeks|month|monthes|year|years|decade|decades|century|centuries|millennium|millenniums){1,1}[ \\t]+)+([ \\t]+ago){0,1}$", 1 TSRMLS_CC) == FAILURE &&
- php_pgsql_convert_match(Z_STRVAL_PP(val), "^@[ \\t]+[+-]{0,1}[ \\t]+(second|seconds|minute|minute|hour|hour|day|days|week|weeks|month|monthes|year|years|decade|decades|century|centuries|millennium|millenniums){1,1}[ \\t]+)+([ \\t]+ago$", 1 TSRMLS_CC) == FAILURE) {
+
+ /* From the Postgres docs:
+
+ interval values can be written with the following syntax:
+ [@] quantity unit [quantity unit...] [direction]
+
+ Where: quantity is a number (possibly signed); unit is second, minute, hour,
+ day, week, month, year, decade, century, millennium, or abbreviations or
+ plurals of these units [note not *all* abbreviations] ; direction can be
+ ago or empty. The at sign (@) is optional noise.
+
+ ...
+
+ Quantities of days, hours, minutes, and seconds can be specified without explicit
+ unit markings. For example, '1 12:59:10' is read the same as '1 day 12 hours 59 min 10
+ sec'.
+ */
+ if (php_pgsql_convert_match(Z_STRVAL_PP(val),
+ "^(@?[ \\t]+)?("
+
+ /* Textual time units and their abbreviations: */
+ "(([-+]?[ \\t]+)?"
+ "[0-9]+(\\.[0-9]*)?[ \\t]*"
+ "(millenniums|millennia|millennium|mil|mils|"
+ "centuries|century|cent|c|"
+ "decades|decade|dec|decs|"
+ "years|year|y|"
+ "months|month|mon|"
+ "weeks|week|w|"
+ "days|day|d|"
+ "hours|hour|hr|hrs|h|"
+ "minutes|minute|mins|min|m|"
+ "seconds|second|secs|sec|s))+|"
+
+ /* Textual time units plus (dd)* hh[:mm[:ss]] */
+ "((([-+]?[ \\t]+)?"
+ "[0-9]+(\\.[0-9]*)?[ \\t]*"
+ "(millenniums|millennia|millennium|mil|mils|"
+ "centuries|century|cent|c|"
+ "decades|decade|dec|decs|"
+ "years|year|y|"
+ "months|month|mon|"
+ "weeks|week|w|"
+ "days|day|d))+"
+ "([-+]?[ \\t]+"
+ "([0-9]+[ \\t]+)+" /* dd */
+ "(([0-9]{1,2}:){0,2}[0-9]{0,2})" /* hh:[mm:[ss]] */
+ ")?))"
+ "([ \\t]+ago)?$",
+ 1 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
- }
+ }
break;
case IS_NULL: