[Groonga-commit] groonga/grnxx at 3bbd51b [master] Gnx: fix a bug that Text columns are broken.

Back to archive index

susumu.yata null+****@clear*****
Tue Apr 7 22:11:45 JST 2015


susumu.yata	2015-04-07 22:11:45 +0900 (Tue, 07 Apr 2015)

  New Revision: 3bbd51b1f4db96ada04ebce702e945d43a5e32b3
  https://github.com/groonga/grnxx/commit/3bbd51b1f4db96ada04ebce702e945d43a5e32b3

  Message:
    Gnx: fix a bug that Text columns are broken.

  Modified files:
    go2/gnx/gnx.go

  Modified: go2/gnx/gnx.go (+11 -5)
===================================================================
--- go2/gnx/gnx.go    2015-04-07 21:44:29 +0900 (4a32490)
+++ go2/gnx/gnx.go    2015-04-07 22:11:45 +0900 (ed09907)
@@ -12,7 +12,7 @@ import "C"
 
 import (
 	"encoding/binary"
-	"encoding/json" // FIXME
+	"encoding/json"
 	"fmt"
 	"hash/fnv"
 	"io/ioutil"
@@ -375,12 +375,15 @@ func (db *GroongaDB) QueryEx(
 
 func (db *GroongaDB) load(
 	tableName string, columnNames []string, records [][]Valuer) (int, error) {
-	jsonRecords, err := json.Marshal(records)
+	jsonBytes, err := json.Marshal(records)
 	if err != nil {
 		return 0, err
 	}
+	jsonString := string(jsonBytes)
+	jsonString = strings.Replace(jsonString, "\\", "\\\\", -1)
+	jsonString = strings.Replace(jsonString, "'", "\\'", -1)
 	command := fmt.Sprintf("load --table '%s' --columns '%s' --values '%s'",
-		tableName, strings.Join(columnNames, ","), string(jsonRecords))
+		tableName, strings.Join(columnNames, ","), jsonString)
 	bytes, err := db.Query(command)
 	if err != nil {
 		return 0, err
@@ -390,12 +393,15 @@ func (db *GroongaDB) load(
 
 func (db *GroongaDB) loadMap(
 	tableName string, recordMaps []map[string]Valuer) (int, error) {
-	jsonRecords, err := json.Marshal(recordMaps)
+	jsonBytes, err := json.Marshal(recordMaps)
 	if err != nil {
 		return 0, err
 	}
+	jsonString := string(jsonBytes)
+	jsonString = strings.Replace(jsonString, "\\", "\\\\", -1)
+	jsonString = strings.Replace(jsonString, "'", "\\'", -1)
 	command := fmt.Sprintf("load --table '%s' --values '%s'",
-		tableName, string(jsonRecords))
+		tableName, jsonString)
 	bytes, err := db.Query(command)
 	if err != nil {
 		return 0, err
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index