Navigation Menu

Skip to content

Commit

Permalink
Gnx: fix a bug that Text columns are broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Apr 7, 2015
1 parent 3773cef commit 3bbd51b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions go2/gnx/gnx.go
Expand Up @@ -12,7 +12,7 @@ import "C"

import (
"encoding/binary"
"encoding/json" // FIXME
"encoding/json"
"fmt"
"hash/fnv"
"io/ioutil"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3bbd51b

Please sign in to comment.