Skip to content
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

Oracle: Create the table is not working #436

Open
jawadpak opened this issue Nov 29, 2022 · 0 comments
Open

Oracle: Create the table is not working #436

jawadpak opened this issue Nov 29, 2022 · 0 comments

Comments

@jawadpak
Copy link

jawadpak commented Nov 29, 2022

I am running the oracle docker on my machine & try to create the table but its giving error " Create tables failed ORA-00922: missing or invalid option" @klaidliadon
I am using the code gorp read.me

func initDb() *gorp.DbMap {
       connectionString := "oracle://sys:jaw@localhost:1521/XE"
       db, err := sql.Open("oracle", connectionString)
	checkErr(err, "sql.Open failed")
       err = db.Ping()
	if err != nil {
		panic(fmt.Errorf("error pinging db: %w", err))
	}
	// construct a gorp DbMap
      dbmap := &gorp.DbMap{Db: db, Dialect: gorp.OracleDialect{}}

       dbmap.AddTableWithName(Product{}, "products").SetKeys(true, "Id")
	// create the table. in a production system you'd generally
	// use a migration tool, or create the tables via scripts
	err = dbmap.CreateTablesIfNotExists()
	checkErr(err, "Create tables failed")
	return dbmap
}

type Product struct {
	Id       int64  `db:"product_id, primarykey, autoincrement"`
	Price    int64  `db:"unit_price"`
	IgnoreMe string `db:"-"`
}

In same way Insert data is also not working, Error "no table found for type: product"
p1 := &Product{9, 5, "Sugar"}
err = dbmap.Insert(p1)

But select query is working & giving correct result

count, err := dbmap.SelectInt("select count(*) from products")
checkErr(err, "select count(*) failed")
log.Println("Rows after inserting:", count)

	var productsData []products
	_, err = dbmap.Select(&productsData , "select * from products order by id")

	
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant