From a4b36620dde7a17656204618b3a86e12ccbfb35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lehrke?= Date: Fri, 18 Jun 2010 09:33:57 +0000 Subject: [PATCH] Fix excess of maximum column length issue --- etemplate/inc/class.so_sql.inc.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/etemplate/inc/class.so_sql.inc.php b/etemplate/inc/class.so_sql.inc.php index fe5e6e0af8..b7f4c12e32 100644 --- a/etemplate/inc/class.so_sql.inc.php +++ b/etemplate/inc/class.so_sql.inc.php @@ -598,7 +598,16 @@ class so_sql { continue; // no need to write that (unset) column } - $data[$db_col] = (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col]; + if ($this->table_def['fd'][$db_col]['type'] == 'varchar' && + strlen($this->data[$col]) > $this->table_def['fd'][$db_col]['precision']) + { + // truncate the field to mamimum length, if upper layers didn't care + $data[$db_col] = substr($this->data[$col],0,$this->table_def['fd'][$db_col]['precision']); + } + else + { + $data[$db_col] = (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col]; + } } } $this->db->insert($this->table_name,$data,false,__LINE__,__FILE__,$this->app);