sam / do fork watch download tarball
public
Rubygem
Description: DataObjects
Homepage: http://rubyforge.org/projects/dorb
Clone URL: git://github.com/sam/do.git
Applied Nikolai Lugovoi's patch. Resolves #270
Sat May 10 11:05:28 -0700 2008
commit  42bb9452cf34de166fba7d98d1d66369f5a727ad
tree    86eca0d0ee35864616df72436edf530865655377
parent  e4b34f49ad69ddd325edafa59ebe0f47e16df3e0
...
527
528
529
530
 
531
532
533
534
535
536
537
 
538
539
540
 
541
542
543
544
545
546
547
 
 
 
 
548
549
550
...
527
528
529
 
530
531
532
533
534
535
536
 
537
538
539
 
540
541
 
 
542
 
 
 
543
544
545
546
547
548
549
0
@@ -527,24 +527,23 @@ static VALUE cCommand_quote_string(VALUE self, VALUE string) {
0
   MYSQL *db = DATA_PTR(rb_iv_get(rb_iv_get(self, "@connection"), "@connection"));
0
   const char *source = StringValuePtr(string);
0
   char *escaped;
0
- char *with_quotes;
0
+ VALUE result;
0
   
0
   int quoted_length = 0;
0
 
0
   // Allocate space for the escaped version of 'string'. Use + 3 allocate space for null term.
0
   // and the leading and trailing single-quotes.
0
   // Thanks to http://www.browardphp.com/mysql_manual_en/manual_MySQL_APIs.html#mysql_real_escape_string  
0
- escaped = (char *)calloc(strlen(source) * 3 + 1, sizeof(char));
0
+ escaped = (char *)calloc(strlen(source) * 3 + 3, sizeof(char));
0
 
0
   // Escape 'source' using the current charset in use on the conection 'db'
0
- quoted_length = mysql_real_escape_string(db, escaped, source, strlen(source));
0
+ quoted_length = mysql_real_escape_string(db, escaped + 1, source, strlen(source));
0
 
0
- // Allocate space for the final version of the quoted string.
0
- with_quotes = (char *)calloc(quoted_length + 3, sizeof(char));
0
   // Wrap the escaped string in single-quotes, this is DO's convention
0
- sprintf(with_quotes, "'%s'", escaped);
0
-
0
- return RUBY_STRING(with_quotes);
0
+ escaped[0] = escaped[quoted_length + 1] = '\'';
0
+ result = rb_str_new(escaped, quoted_length + 2);
0
+ free(escaped);
0
+ return result;
0
 }
0
 
0
 static VALUE build_query_from_args(VALUE klass, int count, VALUE *args) {
...
361
362
363
364
365
 
366
367
368
369
370
371
 
372
373
374
 
375
376
377
378
379
380
381
 
 
 
 
 
382
383
384
...
361
362
363
 
364
365
366
367
368
369
370
 
371
372
373
 
374
375
 
 
376
 
 
 
377
378
379
380
381
382
383
384
0
@@ -361,24 +361,24 @@ static VALUE cCommand_quote_string(VALUE self, VALUE string) {
0
   size_t length;
0
   const char *source = StringValuePtr(string);
0
   char *escaped;
0
- char *with_quotes;
0
   int quoted_length = 0;
0
+ VALUE result;
0
   
0
   length = strlen(source);
0
 
0
   // Allocate space for the escaped version of 'string'
0
   // http://www.postgresql.org/docs/8.3/static/libpq-exec.html#LIBPQ-EXEC-ESCAPE-STRING
0
- escaped = (char *)calloc(strlen(source) * 2 + 1, sizeof(char));
0
+ escaped = (char *)calloc(strlen(source) * 2 + 3, sizeof(char));
0
 
0
   // Escape 'source' using the current charset in use on the conection 'db'
0
- quoted_length = PQescapeStringConn(db, escaped, source, length, NULL);
0
+ quoted_length = PQescapeStringConn(db, escaped + 1, source, length, NULL);
0
 
0
- // Allocate space for the final version of the quoted string.
0
- with_quotes = (char *)calloc(quoted_length + 3, sizeof(char));
0
   // Wrap the escaped string in single-quotes, this is DO's convention
0
- sprintf(with_quotes, "'%s'", escaped);
0
-
0
- return rb_str_new2(with_quotes);
0
+ escaped[quoted_length + 1] = escaped[0] = '\'';
0
+
0
+ result = rb_str_new(escaped, quoted_length + 2);
0
+ free(escaped);
0
+ return result;
0
 }
0
 
0
 static VALUE cCommand_execute_non_query(int argc, VALUE *argv[], VALUE self) {

Comments

    No one has commented yet.