diff options
author | Derek Jones <derek.jones@ellislab.com> | 2008-01-22 22:13:12 +0100 |
---|---|---|
committer | Derek Jones <derek.jones@ellislab.com> | 2008-01-22 22:13:12 +0100 |
commit | 2e061440560701f68dd2d65d8d56355f4bdfe6f4 (patch) | |
tree | 8949cbe20d60461f3ee3e74a771b9726a925bbbb | |
parent | 77fee9affdd28c647759965aec20028aeb1d8798 (diff) |
added enclosures to csv_from _result()
-rw-r--r-- | system/database/DB_utility.php | 9 | ||||
-rw-r--r-- | user_guide/changelog.html | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 9b78aa8ec..d9b8fed74 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -168,11 +168,12 @@ class CI_DB_utility extends CI_DB_forge { *
* @access public
* @param object The query result object
- * @param string The delimiter - tab by default
+ * @param string The delimiter - comma by default
* @param string The newline character - \n by default
+ * @param string The enclosure - double quote by default
* @return string
*/
- function csv_from_result($query, $delim = "\t", $newline = "\n")
+ function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"')
{
if ( ! is_object($query) OR ! method_exists($query, 'field_names'))
{
@@ -184,7 +185,7 @@ class CI_DB_utility extends CI_DB_forge { // First generate the headings from the table column names
foreach ($query->list_fields() as $name)
{
- $out .= $name.$delim;
+ $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim;
}
$out = rtrim($out);
@@ -195,7 +196,7 @@ class CI_DB_utility extends CI_DB_forge { {
foreach ($row as $item)
{
- $out .= $item.$delim;
+ $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim;
}
$out = rtrim($out);
$out .= $newline;
diff --git a/user_guide/changelog.html b/user_guide/changelog.html index a6a367b28..adbd500e9 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -92,6 +92,7 @@ Change Log <li>Added a check for NULL fields in the MySQL database backup utility.</li>
<li>Added "constrain_by_prefix" parameter to db->list_table() function. If set to TRUE it will limit the result to only table names with the current prefix.</li>
<li>Deprecated from Active Record; <kbd>getwhere()</kbd> for <kbd>get_where()</kbd>; <kbd>groupby()</kbd> for <kbd>group_by()</kbd>; <kbd>havingor()</kbd> for <kbd>having_or()</kbd>; <kbd>orderby()</kbd> for <kbd>order_by</kbd>; <kbd>orwhere()</kbd> for <kbd>or_where()</kbd>; and <kbd>orlike()</kbd> for <kbd>or_like()</kbd>.</li>
+ <li>Modified <kbd>csv_from_result()</kbd> to output CSV data more in the spirit of basic rules of RFC 4180.</li>
</ul>
</li>
@@ -154,7 +155,8 @@ Change Log <ul>
<li>Removed an extraneous call to loading models (#3286).</li>
- <li>Removed extraneous load of $CFG in _display_cache() of the Output class</li>
+ <li>Removed extraneous load of $CFG in _display_cache() of the Output class (#3285)</li>
+ <li>Fixed a bug (#1890) in csv_from_result() where content that included the delimiter would break the file.</li>
<li>Fixed a bug (#3156) in Text Helper highlight_code() causing PHP tags to be handled incorrectly.</li>
<li>Fixed a bug (#3289) in the File Helper where temp files in directories being tested with is_really_writable() were not being handled properly</li>
<li>Fixed a bug (#3279) where the Email class was sending the wrong Content-Transfer-Encoding for some character sets.</li>
|