From f3bafdae5d5da476ed51343dca4a57b4180869bd Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 16 Apr 2013 15:59:17 -0700 Subject: [PATCH] Added truncate() function. Switched default FIELD_TYPE to escape() instead of toDB() (which was causing serious BC issues) --- e107_handlers/mysql_class.php | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php index 2f2b9a6d4..d5768b456 100644 --- a/e107_handlers/mysql_class.php +++ b/e107_handlers/mysql_class.php @@ -680,7 +680,7 @@ class e_db_mysql function replace($table, $arg, $debug = FALSE, $log_type = '', $log_remark = '') { $arg['_REPLACE'] = TRUE; - return $this->db_Insert($table, $arg, $debug, $log_type, $log_remark); + return $this->insert($table, $arg, $debug, $log_type, $log_remark); } /** @@ -848,10 +848,6 @@ class e_db_mysql return ($fieldValue && $fieldValue !== 'NULL' ? "'".$this->escape($fieldValue, false)."'" : 'NULL'); break; - case 'escape': - return "'".$this->escape($fieldValue, false)."'"; - break; - case 'array': if(is_array($fieldValue)) { @@ -860,11 +856,15 @@ class e_db_mysql return "'". (string) $fieldValue."'"; break; - case 'todb': - default: + case 'todb': // using as default causes serious BC issues. if($fieldValue == '') { return "''"; } return "'".e107::getParser()->toDB($fieldValue)."'"; break; + + case 'escape': + default: + return "'".$this->escape($fieldValue, false)."'"; + break; } } @@ -912,6 +912,17 @@ class e_db_mysql } } + /** + * Truncate a table + * @param string $table - table name without e107 prefix + */ + function truncate($table=null) + { + if($table == null){ return; } + return $this->gen("TRUNCATE TABLE `#".$table."` "); + } + + /** * @return array MySQL row * @param string $mode @@ -2060,9 +2071,13 @@ class e_db_mysql case 'char' : case 'text' : case 'varchar' : - $outDefs['_FIELD_TYPES'][$v['name']] = 'todb'; + $outDefs['_FIELD_TYPES'][$v['name']] = 'escape'; //XXX toDB() causes serious BC issues. break; } + + // if($v['name']) + + if (isset($v['nulltype']) && !isset($v['default'])) { $outDefs['_NOTNULL'][$v['name']] = '';