Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed old examples for now

  • Loading branch information...
commit 146f03e26568e1fcb94dd93bb57ceed0a9b0b2ba 1 parent 71ddeea
@Philio authored
View
23 Examples/makefile
@@ -1,23 +0,0 @@
-include $(GOROOT)/src/Make.inc
-
-EXAMPLES = query reconnect statement
-
-all: $(EXAMPLES)
-
-query:
- $(GC) -o $(@).$(O) $(@).go
- $(LD) -s -o $(@) $(@).$(O)
-
-reconnect:
- $(GC) -o $(@).$(O) $(@).go
- $(LD) -s -o $(@) $(@).$(O)
-
-statement:
- $(GC) -o $(@).$(O) $(@).go
- $(LD) -s -o $(@) $(@).$(O)
-
-clean:
- rm -rf *.[568oa] $(EXAMPLES)
-
-
-
View
69 Examples/query.go
@@ -1,69 +0,0 @@
-// Query example for GoMySQL
-// This script will get the first 5 rows from table test1
-package main
-
-import (
- "mysql"
- "fmt"
- "os"
- "flag"
-)
-
-var (
- dbhost = flag.String("host", "", "Database server address.")
- dbuser = flag.String("user", "", "Database username.")
- dbpass = flag.String("pass", "", "Database password.")
- dbname = flag.String("db", "", "Database name.")
-)
-
-func main() {
- flag.Parse()
-
- if *dbhost == "" || *dbname == "" || *dbuser == "" {
- flag.Usage()
- os.Exit(1)
- }
-
- var err os.Error
- var res *mysql.MySQLResult
- var row map[string]interface{}
- var key string
- var value interface{}
-
- // Create new instance
- db := mysql.New()
-
- // Enable logging
- db.Logging = true
-
- // Connect to database
- if err = db.Connect(*dbhost, *dbuser, *dbpass, *dbname); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- os.Exit(1)
- }
-
- defer db.Close()
-
- // Use UTF8
- if _, err = db.Query("SET NAMES utf8"); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- return
- }
-
- // Query database
- if res, err = db.Query("SELECT * FROM test1 LIMIT 5"); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- return
- }
-
- for {
- if row = res.FetchMap(); row == nil {
- break
- }
-
- for key, value = range row {
- fmt.Printf("%s:%v\n", key, value)
- }
- }
-
-}
View
77 Examples/reconnect.go
@@ -1,77 +0,0 @@
-// Reconnect example for GoMySQL
-// This script will run forever, reconnect can be tested by restarting MySQL
-// server while script is running.
-package main
-
-import (
- "mysql"
- "fmt"
- "os"
- "time"
- "flag"
-)
-
-var (
- dbhost = flag.String("host", "", "Database server address.")
- dbuser = flag.String("user", "", "Database username.")
- dbpass = flag.String("pass", "", "Database password.")
- dbname = flag.String("db", "", "Database name.")
-)
-
-// Reconnect function, attempts to reconnect once per second
-func reconnect(db *mysql.MySQL, done chan bool) {
- var err os.Error
- attempts := 0
-
- for {
- // Sleep for 1 second
- time.Sleep(1e9)
-
- // Attempt to reconnect
- if err = db.Reconnect(); err != nil {
- break
- }
-
- attempts++
- fmt.Fprintf(os.Stderr, "Reconnect attempt %d failed\n", attempts)
- }
-
- done <- true
-}
-
-func main() {
- flag.Parse()
-
- if *dbhost == "" || *dbname == "" || *dbuser == "" {
- flag.Usage()
- os.Exit(1)
- }
-
- var err os.Error
-
- // Create new instance
- db := mysql.New()
-
- // Connect to database
- if err = db.Connect(*dbhost, *dbuser, *dbpass, *dbname); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- os.Exit(1)
- }
-
- // Ensure connection is closed on exit.
- defer db.Close()
-
- done := make(chan bool)
-
- // Repeat query forever
- for {
- if _, err = db.Query("SELECT * FROM test1 LIMIT 5"); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- go reconnect(db, done)
- <-done
- }
-
- // Sleep for 0.5 seconds
- time.Sleep(5e8)
- }
-}
View
85 Examples/statement.go
@@ -1,85 +0,0 @@
-// Statement example for GoMySQL
-// This script will get rows where id is between 1 and 5
-package main
-
-import (
- "mysql"
- "fmt"
- "os"
- "flag"
-)
-
-var (
- dbhost = flag.String("host", "", "Database server address.")
- dbuser = flag.String("user", "", "Database username.")
- dbpass = flag.String("pass", "", "Database password.")
- dbname = flag.String("db", "", "Database name.")
-)
-
-func main() {
- flag.Parse()
-
- if *dbhost == "" || *dbname == "" || *dbuser == "" {
- flag.Usage()
- os.Exit(1)
- }
-
- var err os.Error
- var res *mysql.MySQLResult
- var row map[string]interface{}
- var key string
- var value interface{}
- var stmt *mysql.MySQLStatement
-
- // Create new instance
- db := mysql.New()
-
- // Connect to database
- if err = db.Connect(*dbhost, *dbuser, *dbpass, *dbname); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- os.Exit(1)
- }
-
- // Ensure connection is closed on exit.
- defer db.Close()
-
- // Use UTF8
- if _, err = db.Query("SET NAMES utf8"); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- return
- }
-
- // Initialise statement
- if stmt, err = db.InitStmt(); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- return
- }
-
- // Prepare statement
- if err = stmt.Prepare("SELECT * FROM test1 WHERE id > ? AND id < ?"); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- return
- }
-
- // Bind params
- stmt.BindParams(1, 5)
-
- // Execute statement
- if res, err = stmt.Execute(); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- return
- }
-
- defer stmt.Close()
-
- // Display results
- for {
- if row = res.FetchMap(); row == nil {
- break
- }
-
- for key, value = range row {
- fmt.Printf("%s:%v\n", key, value)
- }
- }
-}

0 comments on commit 146f03e

Please sign in to comment.
Something went wrong with that request. Please try again.