Last active
March 3, 2016 00:11
-
-
Save pib/f8c9a4e153e6d226d2ee to your computer and use it in GitHub Desktop.
Revisions
-
pib revised this gist
Mar 3, 2016 . 3 changed files with 13 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,8 +14,10 @@ func main() { log.Fatal(err) } fmt.Println("With no placeholders:") printRows(db.Query("SELECT id, lat, lon FROM lat_lons WHERE id IN(1, 2)")) fmt.Println("\nWith placeholder:") printRows(db.Query("SELECT id, lat, lon FROM lat_lons WHERE id IN(?, ?)", 1, 2)) } @@ -36,4 +38,4 @@ func printRows(rows *sql.Rows, err error) { fmt.Println(id, *lat, *lon) } rows.Close() } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ CREATE TABLE `lat_lons` ( `id` int, `lat` float, `lon` float ); INSERT INTO `lat_lons` VALUES (1, 33.9534, -117.396); INSERT INTO `lat_lons` VALUES (2, 35.7942, -115.401); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ With no placeholders: 1 33.9534 -117.396 2 35.7942 -115.401 With placeholder: 1 33.953399658203125 -117.39600372314453 2 35.7942008972168 -115.4010009765625 -
pib created this gist
Mar 3, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ package main import ( "database/sql" "fmt" "log" _ "github.com/go-sql-driver/mysql" ) func main() { db, err := sql.Open("mysql", "root:@tcp(localhost:3306)/float_bug") if err != nil { log.Fatal(err) } printRows(db.Query("SELECT id, lat, lon FROM lat_lons WHERE id = 1")) printRows(db.Query("SELECT id, lat, lon FROM lat_lons WHERE id = ?", 1)) } func printRows(rows *sql.Rows, err error) { if err != nil { log.Fatal(err) } var ( id int lat, lon *float64 ) for rows.Next() { if err = rows.Scan(&id, &lat, &lon); err != nil { log.Fatal(err) } fmt.Println(id, *lat, *lon) } rows.Close() } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ DROP TABLE `lat_lons`; CREATE TABLE `lat_lons` ( `id` int, `lat` float, `lon` float ); INSERT INTO `lat_lons` VALUES (1, 33.9534, -117.396);