Permalink
Browse files

merge dev->master

  • Loading branch information...
2 parents ef53a0f + 14ae027 commit 46be3af94682f71eedd2d1981f4a0fc5c42f9dd9 Philio committed Feb 25, 2011
Showing with 4,120 additions and 3,486 deletions.
  1. +0 −23 Examples/makefile
  2. +0 −69 Examples/query.go
  3. +0 −77 Examples/reconnect.go
  4. +0 −85 Examples/statement.go
  5. +27 −0 LICENSE
  6. +12 −1 Makefile
  7. +210 −161 README.markdown
  8. +171 −0 const.go
  9. +295 −0 convert.go
  10. +135 −0 error.go
  11. +367 −0 handler.go
  12. +707 −583 mysql.go
  13. +0 −133 mysql_const.go
  14. +0 −37 mysql_error.go
  15. +0 −1,444 mysql_packet.go
  16. +0 −158 mysql_result.go
  17. +0 −715 mysql_statement.go
  18. +268 −0 mysql_test.go
  19. +782 −0 packet.go
  20. +112 −0 password.go
  21. +143 −0 reader.go
  22. +128 −0 result.go
  23. +657 −0 statement.go
  24. +47 −0 types.go
  25. +59 −0 writer.go
View
@@ -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
@@ -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
@@ -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
@@ -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)
- }
- }
-}
View
27 LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2010/2011, Phil Bayfield "Philio"
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Phil Bayfield nor the names of contributors may be
+ used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -1,6 +1,17 @@
include $(GOROOT)/src/Make.inc
TARG=mysql
-GOFILES=mysql.go mysql_const.go mysql_error.go mysql_packet.go mysql_result.go mysql_statement.go
+GOFILES=mysql.go\
+ types.go\
+ const.go\
+ error.go\
+ password.go\
+ reader.go\
+ writer.go\
+ packet.go\
+ convert.go\
+ handler.go\
+ result.go\
+ statement.go
include $(GOROOT)/src/Make.pkg
Oops, something went wrong.

0 comments on commit 46be3af

Please sign in to comment.