Skip to content

Commit

Permalink
update README.md and add example for LONG data type
Browse files Browse the repository at this point in the history
  • Loading branch information
sijms committed Mar 26, 2023
1 parent 0f0eb1c commit 923aa6c
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
always ensure that you get latest release
- See examples for more help
```

### version 2.6.8: Fix return long data type with lob prefetch option:
* know you can return up to 0x3FFFFFFF of data from long coumn type
* examples/long insert 0x3FFF bytes of data into long column and query it again
* for large data size better use `lob fetch=post`
### version 2.6.5: Add New Url Options (Language and Territory)
* this will control the language of the server messages
```golang
Expand Down
111 changes: 111 additions & 0 deletions examples/long/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package main

import (
"database/sql"
"fmt"
_ "github.com/sijms/go-ora/v2"
"os"
"strings"
"time"
)

var longText = strings.Repeat("*", 0x3FFF)

func createTable(conn *sql.DB) error {
t := time.Now()
sqlText := `CREATE TABLE GOORA_TEMP_LONG(
ID number(10) NOT NULL,
NAME VARCHAR(200),
NAME_LONG LONG,
VAL number(10,2),
VISIT_DATE date,
PRIMARY KEY(ID)
)`
_, err := conn.Exec(sqlText)
if err != nil {
return err
}
fmt.Println("Finish create table :", time.Now().Sub(t))
return nil
}

func dropTable(conn *sql.DB) error {
t := time.Now()
_, err := conn.Exec("drop table GOORA_TEMP_LONG purge")
if err != nil {
return err
}
fmt.Println("Finish drop table: ", time.Now().Sub(t))
return nil
}

func insertData(conn *sql.DB) error {
t := time.Now()
_, err := conn.Exec(`INSERT INTO GOORA_TEMP_LONG(ID, NAME, NAME_LONG, VAL, VISIT_DATE) VALUES(:1, :2, :3, :4, :5)`,
1, "test name", longText, 1.1, time.Now())
if err != nil {
return err
}
fmt.Println("Finish insert one row: ", time.Now().Sub(t))
return nil

}

func queryData(conn *sql.DB) error {
t := time.Now()
var (
name, nameLong string
val float64
date time.Time
)
err := conn.QueryRow("SELECT NAME, NAME_LONG, VAL, VISIT_DATE FROM GOORA_TEMP_LONG WHERE ID = 1").Scan(&name,
&nameLong, &val, &date)
if err != nil {
return err
}
fmt.Println("name: ", name)
fmt.Println("val: ", val)
fmt.Println("date: ", date)
if longText == nameLong {
fmt.Println("long text equal")
} else {
fmt.Println("long text not equal")
}
fmt.Println("Finish query: ", time.Now().Sub(t))
return nil
}
func main() {
conn, err := sql.Open("oracle", os.Getenv("DSN"))
if err != nil {
fmt.Println("can't open connection: ", err)
return
}
defer func() {
err = conn.Close()
if err != nil {
fmt.Println("can't close connection: ", err)
}
}()

err = createTable(conn)
if err != nil {
fmt.Println("can't create table: ", err)
return
}
defer func() {
err = dropTable(conn)
if err != nil {
fmt.Println("can't drop table: ", err)
}
}()

err = insertData(conn)
if err != nil {
fmt.Println("can't insert data: ", err)
return
}
err = queryData(conn)
if err != nil {
fmt.Println("can't query: ", err)
}
}

0 comments on commit 923aa6c

Please sign in to comment.