diff -urpN drupal-6.x-dev-200707182104/includes/cache.inc drupal-6.x-dev-clob-0.7/includes/cache.inc --- drupal-6.x-dev-200707182104/includes/cache.inc 2007-05-26 05:01:30.000000000 +0800 +++ drupal-6.x-dev-clob-0.7/includes/cache.inc 2007-07-18 21:19:09.000000000 +0800 @@ -105,10 +105,11 @@ function cache_set($cid, $data, $table = $serialized = 1; } $created = time(); - db_query("UPDATE {". $table ."} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, $created, $expire, $headers, $serialized, $cid); + db_query("UPDATE {". $table ."} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", NULL, $created, $expire, $headers, $serialized, $cid); if (!db_affected_rows()) { - @db_query("INSERT INTO {". $table ."} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, $created, $expire, $headers, $serialized); + @db_query("INSERT INTO {". $table ."} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, NULL, $created, $expire, $headers, $serialized); } + db_update_blob(db_prefix_tables('{' . $table . '}'), array('data' => $data), "cid = '%s'", $cid); } /** diff -urpN drupal-6.x-dev-200707182104/includes/database.inc drupal-6.x-dev-clob-0.7/includes/database.inc --- drupal-6.x-dev-200707182104/includes/database.inc 2007-07-12 17:21:30.000000000 +0800 +++ drupal-6.x-dev-clob-0.7/includes/database.inc 2007-07-18 21:19:09.000000000 +0800 @@ -158,6 +158,9 @@ function db_set_active($name = 'default' /** * Helper function for db_query(). + * + * NOTE: %b and %c should input NULL as placeholder, and further more + * update its value manually by using db_update_blob() or db_update_clob(). */ function _db_query_callback($match, $init = FALSE) { static $args = NULL; @@ -175,15 +178,17 @@ function _db_query_callback($match, $ini return '%'; case '%f': return (float) array_shift($args); - case '%b': // binary data - return db_encode_blob(array_shift($args)); + case '%b': // Binary Large OBject. + return db_encode_blob(array_shift($args)); + case '%c': // Character Large OBject. + return db_encode_clob(array_shift($args)); } } /** * Indicates the place holders that should be replaced in _db_query_callback(). */ -define('DB_QUERY_REGEXP', '/(%d|%s|%%|%f|%b)/'); +define('DB_QUERY_REGEXP', '/(%d|%s|%%|%f|%b|%c)/'); /** * Helper function for db_rewrite_sql. diff -urpN drupal-6.x-dev-200707182104/includes/database.mysql-common.inc drupal-6.x-dev-clob-0.7/includes/database.mysql-common.inc --- drupal-6.x-dev-200707182104/includes/database.mysql-common.inc 2007-06-27 04:24:19.000000000 +0800 +++ drupal-6.x-dev-clob-0.7/includes/database.mysql-common.inc 2007-07-18 21:19:09.000000000 +0800 @@ -27,7 +27,7 @@ * you may also pass a single array containing the query arguments. * * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose - * in '') and %%. + * in ''), %c (character large object, do not enclose in '') and %%. * * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, * and TRUE values to decimal 1. @@ -217,6 +217,9 @@ function db_type_map() { 'blob:big' => 'LONGBLOB', 'blob:normal' => 'BLOB', + 'clob:big' => 'LONGTEXT', + 'clob:normal' => 'TEXT', + 'datetime:normal' => 'DATETIME', ); return $map; @@ -462,7 +465,98 @@ function db_last_insert_id($table, $fiel } /** + * Update Character Large Object value. Wrapper function for _db_update_lob() + * + * @param $table + * Table to update. + * @param $values + * Values to update, in array format. Columns and values pairs. + * @param $where + * Update condition. + * @param ... + * A variable number of arguments which are substituted into the query + * WHERE condition, using printf() syntax. Instead of a variable number + * of query arguments, you may also pass a single array containing the + * query arguments. + * + * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose + * in ''), %c (character large object, do not enclose in '') and %%. + * + * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, + * and TRUE values to decimal 1. + * + * @return + * Returns TRUE on success or FALSE on failure. + */ +function db_update_blob($table, $values, $where) { + $args = func_get_args(); + array_shift($args); + array_shift($args); + array_shift($args); + $args = is_array($args) ? $args : array($args); + if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax + $args = $args[0]; + } + return _db_update_lob($table, $values, $where, $args, 'BLOB'); +} + +/** + * Update Binary Large Object value. Wrapper function for _db_update_lob() + * + * @param $table + * Table to update. + * @param $values + * Values to update, in array format. Columns and values pairs. + * @param $where + * Update condition. + * @param ... + * A variable number of arguments which are substituted into the query + * WHERE condition, using printf() syntax. Instead of a variable number + * of query arguments, you may also pass a single array containing the + * query arguments. + * + * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose + * in ''), %c (character large object, do not enclose in '') and %%. + * + * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, + * and TRUE values to decimal 1. + * + * @return + * Returns TRUE on success or FALSE on failure. + */ +function db_update_clob($table, $values, $where) { + $args = func_get_args(); + array_shift($args); + array_shift($args); + array_shift($args); + $args = is_array($args) ? $args : array($args); + if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax + $args = $args[0]; + } + return _db_update_lob($table, $values, $where, $args, 'CLOB'); +} + +/** + * Helper function for update Large Object value. + */ +function _db_update_lob($table, $values, $where, $args, $lobtype = 'BLOB') { + _db_query_callback($args, TRUE); + $where = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $where); + + $arr = array(); + foreach ($values as $key => $value) { + switch ($lobtype) { + case 'BLOB': $arr[] = $key . " = " . db_encode_blob($value); break; + case 'CLOB': $arr[] = $key . " = " . db_encode_clob($value); break; + } + } + + $query = 'UPDATE ' . $table . ' SET ' . implode(', ', $arr) . ' WHERE ' . $where; + return _db_query($query); +} + +/** * @} End of "ingroup schemaapi". */ -?> \ No newline at end of file +?> diff -urpN drupal-6.x-dev-200707182104/includes/database.mysqli.inc drupal-6.x-dev-clob-0.7/includes/database.mysqli.inc --- drupal-6.x-dev-200707182104/includes/database.mysqli.inc 2007-06-05 20:13:20.000000000 +0800 +++ drupal-6.x-dev-clob-0.7/includes/database.mysqli.inc 2007-07-18 21:19:09.000000000 +0800 @@ -253,7 +253,7 @@ function db_affected_rows() { * using printf() syntax. The query arguments can be enclosed in one * array instead. * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose - * in '') and %%. + * in ''), %c (character large object, do not enclose in '') and %%. * * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, * and TRUE values to decimal 1. @@ -303,7 +303,7 @@ function db_query_range($query) { * using printf() syntax. The query arguments can be enclosed in one * array instead. * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose - * in '') and %%. + * in ''), %c (character large object, do not enclose in '') and %%. * * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, * and TRUE values to decimal 1. @@ -335,11 +335,11 @@ function db_query_temporary($query) { * @param $data * Data to encode. * @return - * Encoded data. + * Encoded data. Return a place holder when NULL input. */ function db_encode_blob($data) { global $active_db; - return "'". mysqli_real_escape_string($active_db, $data) ."'"; + return !is_null($data) ? "'". mysqli_real_escape_string($active_db, $data) ."'" : "''"; } /** @@ -355,6 +355,31 @@ function db_decode_blob($data) { } /** + * Returns a properly formatted Character Large OBject value. + * + * @param $data + * Data to encode. + * @return + * Encoded data. Return a place holder when NULL input. + */ +function db_encode_clob($data) { + global $active_db; + return !is_null($data) ? "'". mysqli_real_escape_string($active_db, $data) ."'" : "''"; +} + +/** + * Returns text from a Character Large OBject value. + * + * @param $data + * Data to decode. + * @return + * Decoded data. + */ +function db_decode_clob($data) { + return $data; +} + +/** * Prepare user input for use in a database query, preventing SQL injection attacks. */ function db_escape_string($text) { diff -urpN drupal-6.x-dev-200707182104/includes/database.mysql.inc drupal-6.x-dev-clob-0.7/includes/database.mysql.inc --- drupal-6.x-dev-200707182104/includes/database.mysql.inc 2007-06-05 20:13:20.000000000 +0800 +++ drupal-6.x-dev-clob-0.7/includes/database.mysql.inc 2007-07-18 21:19:09.000000000 +0800 @@ -255,7 +255,7 @@ function db_affected_rows() { * using printf() syntax. The query arguments can be enclosed in one * array instead. * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose - * in '') and %%. + * in ''), %c (character large object, do not enclose in '') and %%. * * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, * and TRUE values to decimal 1. @@ -305,7 +305,7 @@ function db_query_range($query) { * using printf() syntax. The query arguments can be enclosed in one * array instead. * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose - * in '') and %%. + * in ''), %c (character large object, do not enclose in '') and %%. * * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, * and TRUE values to decimal 1. @@ -337,11 +337,11 @@ function db_query_temporary($query) { * @param $data * Data to encode. * @return - * Encoded data. + * Encoded data. Return a place holder when NULL input. */ function db_encode_blob($data) { global $active_db; - return "'". mysql_real_escape_string($data, $active_db) ."'"; + return !is_null($data) ? "'". mysql_real_escape_string($data, $active_db) ."'" : "''"; } /** @@ -357,6 +357,29 @@ function db_decode_blob($data) { } /** + * Returns a placeholder for Character Large OBject value. + * + * @return + * Placeholder. + */ +function db_encode_clob($data) { + global $active_db; + return !is_null($data) ? "'". mysql_real_escape_string($data, $active_db) ."'" : "''"; +} + +/** + * Returns text from a Character Large Object value. + * + * @param $data + * Data to decode. + * @return + * Decoded data. + */ +function db_decode_clob($data) { + return $data; +} + +/** * Prepare user input for use in a database query, preventing SQL injection attacks. */ function db_escape_string($text) { diff -urpN drupal-6.x-dev-200707182104/includes/database.pgsql.inc drupal-6.x-dev-clob-0.7/includes/database.pgsql.inc --- drupal-6.x-dev-200707182104/includes/database.pgsql.inc 2007-07-05 16:48:57.000000000 +0800 +++ drupal-6.x-dev-clob-0.7/includes/database.pgsql.inc 2007-07-18 21:19:09.000000000 +0800 @@ -120,7 +120,7 @@ function db_connect($url) { * you may also pass a single array containing the query arguments. * * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose - * in '') and %%. + * in ''), %c (character large object, do not enclose in '') and %%. * * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, * and TRUE values to decimal 1. @@ -287,7 +287,7 @@ function db_affected_rows() { * using printf() syntax. Instead of a variable number of query arguments, * you may also pass a single array containing the query arguments. * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose - * in '') and %%. + * in ''), %c (character large object, do not enclose in '') and %%. * * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, * and TRUE values to decimal 1. @@ -337,7 +337,7 @@ function db_query_range($query) { * using printf() syntax. The query arguments can be enclosed in one * array instead. * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose - * in '') and %%. + * in ''), %c (character large object, do not enclose in '') and %%. * * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, * and TRUE values to decimal 1. @@ -370,10 +370,10 @@ function db_query_temporary($query) { * @param $data * Data to encode. * @return - * Encoded data. + * Encoded data. Return a place holder when NULL input. */ function db_encode_blob($data) { - return "'". pg_escape_bytea($data) ."'"; + return !is_null($data) ? "'". pg_escape_bytea($data) ."'" : "''"; } /** @@ -390,6 +390,32 @@ function db_decode_blob($data) { } /** + * Returns a properly formatted Character Large OBject value. + * + * @param $data + * Data to encode. + * @return + * Encoded data. Return a place holder when NULL input. + */ +function db_encode_clob($data) { + return !is_null($data) ? "'". pg_escape_string($data) ."'" : "''"; + +} + +/** + * Returns text from a Character Large OBject value. + * In case of PostgreSQL decodes data after select from bytea field. + * + * @param $data + * Data to decode. + * @return + * Decoded data. + */ +function db_decode_clob($data) { + return $data; +} + +/** * Prepare user input for use in a database query, preventing SQL injection attacks. * Note: This function requires PostgreSQL 7.2 or later. */ @@ -398,6 +424,97 @@ function db_escape_string($text) { } /** + * Update Character Large Object value. Wrapper function for _db_update_lob() + * + * @param $table + * Table to update. + * @param $values + * Values to update, in array format. Columns and values pairs. + * @param $where + * Update condition. + * @param ... + * A variable number of arguments which are substituted into the query + * WHERE condition, using printf() syntax. Instead of a variable number + * of query arguments, you may also pass a single array containing the + * query arguments. + * + * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose + * in ''), %c (character large object, do not enclose in '') and %%. + * + * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, + * and TRUE values to decimal 1. + * + * @return + * Returns TRUE on success or FALSE on failure. + */ +function db_update_blob($table, $values, $where) { + $args = func_get_args(); + array_shift($args); + array_shift($args); + array_shift($args); + $args = is_array($args) ? $args : array($args); + if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax + $args = $args[0]; + } + return _db_update_lob($table, $values, $where, $args, 'BLOB'); +} + +/** + * Update Binary Large Object value. Wrapper function for _db_update_lob() + * + * @param $table + * Table to update. + * @param $values + * Values to update, in array format. Columns and values pairs. + * @param $where + * Update condition. + * @param ... + * A variable number of arguments which are substituted into the query + * WHERE condition, using printf() syntax. Instead of a variable number + * of query arguments, you may also pass a single array containing the + * query arguments. + * + * Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose + * in ''), %c (character large object, do not enclose in '') and %%. + * + * NOTE: using this syntax will cast NULL and FALSE values to decimal 0, + * and TRUE values to decimal 1. + * + * @return + * Returns TRUE on success or FALSE on failure. + */ +function db_update_clob($table, $values, $where) { + $args = func_get_args(); + array_shift($args); + array_shift($args); + array_shift($args); + $args = is_array($args) ? $args : array($args); + if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax + $args = $args[0]; + } + return _db_update_lob($table, $values, $where, $args, 'CLOB'); +} + +/** + * Helper function for update Large Object value. + */ +function _db_update_lob($table, $values, $where, $args, $lobtype = 'BLOB') { + _db_query_callback($args, TRUE); + $where = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $where); + + $arr = array(); + foreach ($values as $key => $value) { + switch ($lobtype) { + case 'BLOB': $arr[] = $key . " = " . db_encode_blob($value); break; + case 'CLOB': $arr[] = $key . " = " . db_encode_clob($value); break; + } + } + + $query = 'UPDATE ' . $table . ' SET ' . implode(', ', $arr) . ' WHERE ' . $where; + return _db_query($query); +} + +/** * Lock a table. * This function automatically starts a transaction. */ @@ -501,6 +618,9 @@ function db_type_map() { 'blob:big' => 'bytea', 'blob:normal' => 'bytea', + 'clob:big' => 'text', + 'clob:normal' => 'text', + 'datetime:normal' => 'timestamp', 'serial:tiny' => 'serial', diff -urpN drupal-6.x-dev-200707182104/modules/aggregator/aggregator.module drupal-6.x-dev-clob-0.7/modules/aggregator/aggregator.module --- drupal-6.x-dev-200707182104/modules/aggregator/aggregator.module 2007-07-16 20:43:04.000000000 +0800 +++ drupal-6.x-dev-clob-0.7/modules/aggregator/aggregator.module 2007-07-18 21:19:09.000000000 +0800 @@ -977,15 +977,17 @@ function aggregator_parse_feed(&$data, $ function aggregator_save_item($edit) { if ($edit['iid'] && $edit['title']) { - db_query("UPDATE {aggregator_item} SET title = '%s', link = '%s', author = '%s', description = '%s', guid = '%s', timestamp = %d WHERE iid = %d", $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['guid'], $edit['timestamp'], $edit['iid']); + db_query("UPDATE {aggregator_item} SET title = '%s', link = '%s', author = '%s', description = %c, guid = '%s', timestamp = %d WHERE iid = %d", $edit['title'], $edit['link'], $edit['author'], NULL, $edit['guid'], $edit['timestamp'], $edit['iid']); + db_update_clob(db_prefix_tables('{aggregator_item}'), array('description' => $edit['description']), 'iid = %d', $edit['iid']); } else if ($edit['iid']) { db_query('DELETE FROM {aggregator_item} WHERE iid = %d', $edit['iid']); db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $edit['iid']); } else if ($edit['title'] && $edit['link']) { - db_query("INSERT INTO {aggregator_item} (fid, title, link, author, description, timestamp, guid) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s')", $edit['fid'], $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['timestamp'], $edit['guid']); + db_query("INSERT INTO {aggregator_item} (fid, title, link, author, description, timestamp, guid) VALUES (%d, '%s', '%s', '%s', %c, %d, '%s')", $edit['fid'], $edit['title'], $edit['link'], $edit['author'], NULL, $edit['timestamp'], $edit['guid']); $edit['iid'] = db_last_insert_id('aggregator_item', 'iid'); + db_update_clob(db_prefix_tables('{aggregator_item}'), array('description' => $edit['description']), 'iid = %d', $edit['iid']); // file the items in the categories indicated by the feed $categories = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']); while ($category = db_fetch_object($categories)) { @@ -1232,6 +1234,7 @@ function aggregator_page_rss() { } while ($item = db_fetch_object($result)) { + $item->description = db_decode_clob($item->description); switch (variable_get('feed_item_length', 'teaser')) { case 'teaser': $teaser = node_teaser($item->description); @@ -1407,7 +1410,7 @@ function theme_aggregator_page_item($ite $output .= "
\n"; if ($item->description) { - $output .= '