-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes to add simple nzgo example application #33
Open
shabbir10july
wants to merge
1
commit into
master
Choose a base branch
from
shabmoh3_nzgo_examples
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
_ "context" | ||
"database/sql" | ||
"fmt" | ||
_ "log" | ||
|
||
"github.com/IBM/nzgo" | ||
) | ||
|
||
func main() { | ||
|
||
var conninfo string = "host=localhost user=admin password=password dbname=db1 port=5480 sslmode=disable " | ||
|
||
var elog nzgo.PDALogger | ||
elog.LogLevel = "debug" | ||
elog.LogPath = "/tmp/" | ||
elog.Initialize() | ||
|
||
db, err := sql.Open("nzgo", conninfo) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer db.Close() | ||
err = db.Ping() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, _ = db.Exec("drop table t1") | ||
|
||
result, err := db.Exec("create table t1(c1 int,c2 int)") | ||
if err != nil { | ||
fmt.Println("table was not created successfully", err, result) | ||
} else { | ||
fmt.Println("Table created successfully") | ||
} | ||
|
||
result, err = db.Exec("insert into t1 values (1,3)") | ||
if err != nil { | ||
fmt.Println("row was not inserted successfully", err, result) | ||
} else { | ||
rows, _ := result.RowsAffected() | ||
fmt.Println(rows, "row inserted successfully") | ||
|
||
} | ||
|
||
result, err = db.Exec("create external table '/tmp/et10' using ( remotesource 'golang' delimiter '|') as select * from t1;") | ||
if err != nil { | ||
fmt.Println("table was not created successfully", err, result) | ||
} else { | ||
fmt.Println("Table created successfully") | ||
} | ||
|
||
result, err = db.Exec("insert into t1 select * from external '/tmp/et10' using ( remotesource 'golang' delimiter '|' )") | ||
if err != nil { | ||
fmt.Println("row was not inserted successfully", err, result) | ||
} else { | ||
rows, _ := result.RowsAffected() | ||
fmt.Println(rows, "row inserted successfully") | ||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
_ "context" | ||
"database/sql" | ||
"fmt" | ||
_ "log" | ||
|
||
"github.com/IBM/nzgo" | ||
) | ||
|
||
func main() { | ||
|
||
var conninfo string = "host=localhost user=admin password=password dbname=db1 port=5480 sslmode=disable " | ||
|
||
var elog nzgo.PDALogger | ||
elog.LogLevel = "debug" | ||
elog.LogPath = "/tmp/" | ||
elog.Initialize() | ||
|
||
db, err := sql.Open("nzgo", conninfo) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer db.Close() | ||
err = db.Ping() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, _ = db.Exec("drop table t1") | ||
|
||
result, err := db.Exec("create table t1(c1 int,c2 int)") | ||
if err != nil { | ||
fmt.Println("table was not created successfully", err, result) | ||
} else { | ||
fmt.Println("Table created successfully") | ||
} | ||
|
||
result, err = db.Exec("insert into t1 values (1,3)") | ||
if err != nil { | ||
fmt.Println("row was not inserted successfully", err, result) | ||
} else { | ||
rows, _ := result.RowsAffected() | ||
fmt.Println(rows, "row inserted successfully") | ||
|
||
} | ||
var c1, c2 int | ||
rows, err := db.Query("select * from t1;") | ||
if err != nil { | ||
fmt.Println("call to db.Query() failed: ", err) | ||
} | ||
for rows.Next() { | ||
rows.Scan(&c1, &c2) | ||
fmt.Printf("c1 is: %d \n", c1) | ||
fmt.Printf("c2 is: %d \n", c2) | ||
|
||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
_ "log" | ||
|
||
"github.com/IBM/nzgo" | ||
) | ||
|
||
func main() { | ||
|
||
var conninfo string = "host=localhost user=admin password=password dbname=db1 port=5480 sslmode=disable " | ||
|
||
var elog nzgo.PDALogger | ||
elog.LogLevel = "debug" | ||
elog.LogPath = "/tmp/" | ||
elog.Initialize() | ||
|
||
db, err := sql.Open("nzgo", conninfo) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer db.Close() | ||
err = db.Ping() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, _ = db.Exec("drop table t1") | ||
|
||
result, err := db.Exec("create table t1(c1 int,c2 int)") | ||
if err != nil { | ||
fmt.Println("table was not created successfully", err, result) | ||
} else { | ||
fmt.Println("Table created successfully") | ||
} | ||
|
||
result, err = db.Exec("insert into t1 values (1,3)") | ||
if err != nil { | ||
fmt.Println("row was not inserted successfully", err, result) | ||
} else { | ||
rows, _ := result.RowsAffected() | ||
fmt.Println(rows, "row inserted successfully") | ||
|
||
} | ||
|
||
var ctx context.Context | ||
ctx, stop := context.WithCancel(context.Background()) | ||
defer stop() | ||
|
||
var c1, c2 int | ||
rows, err := db.QueryContext(ctx, "SELECT * FROM t1 WHERE c2 =?", 3) | ||
if err != nil { | ||
fmt.Println("error in prepare statement", err) | ||
} | ||
defer rows.Close() | ||
for rows.Next() { | ||
if err := rows.Scan(&c1, &c2); err != nil { | ||
fmt.Println("error in prepare statement", err) | ||
} | ||
fmt.Printf("------------------------ \n") | ||
fmt.Printf("c1 is: %d \n", c1) | ||
fmt.Printf("c2 is: %d \n", c2) | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
_ "context" | ||
"database/sql" | ||
"fmt" | ||
_ "log" | ||
|
||
"github.com/IBM/nzgo" | ||
) | ||
|
||
func main() { | ||
|
||
var conninfo string = "host=localhost user=admin password=password dbname=db1 port=5480 sslmode=disable " | ||
|
||
var elog nzgo.PDALogger | ||
elog.LogLevel = "debug" | ||
elog.LogPath = "/tmp/" | ||
elog.Initialize() | ||
|
||
db, err := sql.Open("nzgo", conninfo) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer db.Close() | ||
err = db.Ping() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer func() { | ||
if err := recover(); err != nil { | ||
fmt.Println("panic occurred:", err) | ||
} | ||
}() | ||
var c1 string | ||
rows, err := db.Query("SELECT jc->'user'->'first_name', jc->'user'->'first_name' from jt") | ||
if err != nil { | ||
fmt.Println(err) | ||
} else { | ||
for rows.Next() { | ||
rows.Scan(&c1) | ||
fmt.Printf("c1 is: %s \n", c1) | ||
} | ||
} | ||
|
||
rows, err = db.Query("SELECT jc->'user'->'first_name' from jt") | ||
if err != nil { | ||
fmt.Println(err) | ||
} else { | ||
for rows.Next() { | ||
rows.Scan(&c1) | ||
fmt.Printf("c1 is: %s \n", c1) | ||
} | ||
} | ||
|
||
} | ||
|
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
_ "log" | ||
|
||
"github.com/IBM/nzgo" | ||
) | ||
|
||
func main() { | ||
|
||
var conninfo string = "host=localhost user=admin password=password dbname=db1 port=5480 sslmode=disable " | ||
|
||
var elog nzgo.PDALogger | ||
elog.LogLevel = "debug" | ||
elog.LogPath = "/tmp/" | ||
elog.Initialize() | ||
|
||
db, err := sql.Open("nzgo", conninfo) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer db.Close() | ||
err = db.Ping() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, _ = db.Exec("drop table t2") | ||
|
||
result, err := db.Exec("create table t2(c1 float4, c2 double, c3 int1, c4 int2, c5 int4, c6 int8, c7 char(5), c8 varchar(10),c9 nchar(50), c10 nvarchar(120),c11 varbinary(12), c12 ST_GEOMETRY(12), DATE_PROD DATE, TIME_PROD TIME, INTERVAL_PROD INTERVAL,TIMESTMP TIMESTAMP,TIMETZ_PROD TIME WITH TIME ZONE, c18 bool);") | ||
if err != nil { | ||
fmt.Println("table was not created successfully", err, result) | ||
} else { | ||
fmt.Println("Table created successfully") | ||
} | ||
|
||
result, err = db.Exec("insert into t2 values (-1,-1,-1,-1,-1,-1,'','','💮€🙇ðŸ›','𩶘€ðˆð¢±‘𩸽',x'68656c6c6f',x'68656c6c6f', '1991-1-1', '12:19:23', '1y4mon3d23h34m67s234565ms', '2016-11-11 03:59:08.8642','12:57:42 AEST', 'yes');") | ||
if err != nil { | ||
fmt.Println("row was not inserted successfully", err, result) | ||
} else { | ||
rows, _ := result.RowsAffected() | ||
fmt.Println(rows, "row inserted successfully") | ||
|
||
} | ||
|
||
result, err = db.Exec("insert into t2 values (-123.345, -23456.789, -128, -32768, -234567, -45678923,'xyz', 'Go lang','💮€🙇ðŸ›','𩶘€ðˆð¢±‘𩸽',x'543b6c6c6f',x'123d6c6f', '2001-12-31', '23:59:59', '5y6mon7d23h21m67s897ms', '1996-12-11 23:59:08.1232','10:47:53 BST', 'false');") | ||
if err != nil { | ||
fmt.Println("row was not inserted successfully", err, result) | ||
} else { | ||
rows, _ := result.RowsAffected() | ||
fmt.Println(rows, "row inserted successfully") | ||
|
||
} | ||
|
||
result, err = db.Exec("insert into t2 values (123.345, 23456.789, 127, 32767, 234567, 45678923,'xyz', 'Go lang','💮€🙇ðŸ›','𩶘€ðˆð¢±‘𩸽',x'543b6c6c6f',x'123d6c6f', '2001-12-31', '23:59:59', '5y6mon7d23h21m67s897ms', '1996-12-11 23:59:08.1232','10:47:53 BST','true');") | ||
if err != nil { | ||
fmt.Println("row was not inserted successfully", err, result) | ||
} else { | ||
rows, _ := result.RowsAffected() | ||
fmt.Println(rows, "row inserted successfully") | ||
|
||
} | ||
|
||
var ctx context.Context | ||
ctx, stop := context.WithCancel(context.Background()) | ||
defer stop() | ||
|
||
var c1 float32 | ||
var c2 float64 | ||
var c3 int8 | ||
var c4 int16 | ||
var c5 int32 | ||
var c6 int64 | ||
var c7, c8, c9, c10, c11, c12, date_prod, time_prod, interval, timestamp, timetz string | ||
var c18 bool | ||
|
||
arg1 := [3]float32{-1, -123.345, 123.345} | ||
arg2 := [3]float64{-1, -23456.789, 23456.789} | ||
|
||
stmt, err := db.PrepareContext(ctx, "select * from t2 where c1 = ? and c2 = ?") | ||
if err != nil { | ||
fmt.Println("error in prepare statement", err) | ||
} | ||
defer stmt.Close() | ||
|
||
for i := 0; i < 3; i++ { | ||
|
||
rows, err := stmt.QueryContext(ctx, arg1[i], arg2[i]) | ||
if err != nil { | ||
fmt.Println("call to stmt.QueryContext() failed: ", err) | ||
} | ||
defer rows.Close() | ||
for rows.Next() { | ||
if err := rows.Scan(&c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, &c9, &c10, &c11, &c12, &date_prod, &time_prod, &interval, ×tamp, &timetz, &c18); err != nil { | ||
fmt.Println("call to rows.Scan() failed: ", err) | ||
} | ||
fmt.Printf("------------------------ \n") | ||
fmt.Printf("c1 is: %f \n", c1) | ||
fmt.Printf("c2 is: %f \n", c2) | ||
fmt.Printf("c3 is: %d \n", c3) | ||
fmt.Printf("c4 is: %d \n", c4) | ||
fmt.Printf("c5 is: %d \n", c5) | ||
fmt.Printf("c6 is: %d \n", c6) | ||
fmt.Printf("c7 is: %s \n", c7) | ||
fmt.Printf("c8 is: %s \n", c8) | ||
fmt.Printf("c9 is: %s \n", c9) | ||
fmt.Printf("c10 is: %s \n", c10) | ||
fmt.Printf("c11 is: %10x \n", c11) | ||
fmt.Printf("c12 is: %10x \n", c12) | ||
fmt.Printf("date_prod is: %s \n", date_prod) | ||
fmt.Printf("time_prod is: %s \n", time_prod) | ||
fmt.Printf("interval is: %s \n", interval) | ||
fmt.Printf("timestamp is: %s \n", timestamp) | ||
fmt.Printf("timetz is: %s \n", timetz) | ||
fmt.Println("c18 is: ", c18) | ||
|
||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required this now.
same in all examples