Compare commits

..

No commits in common. "23806cde4e572579221023ecdb7cc8d6c1bd5973" and "1e1f8bfcf42ffc76cc4e592acab2bf5f618b4499" have entirely different histories.

3 changed files with 0 additions and 41 deletions

5
go.mod
View File

@ -1,5 +0,0 @@
module sql_prase_demo
go 1.20
require github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2

2
go.sum
View File

@ -1,2 +0,0 @@
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY=

34
main.go
View File

@ -1,34 +0,0 @@
package main
import (
"fmt"
"github.com/xwb1989/sqlparser"
)
func main() {
sql := "UPDATE orders, inventory SET orders.status = 'Processed', inventory.stock = inventory.stock - orders.quantity WHERE orders.product_id = inventory.product_id AND orders.id = 1 AND inventory.stock >= orders.quantity"
stmt, err := sqlparser.Parse(sql)
if err != nil {
fmt.Println("Parse error: ", err.Error())
return
}
update, ok := stmt.(*sqlparser.Update)
if !ok {
fmt.Println("Not an UPDATE statement")
return
}
for _, table := range update.TableExprs {
switch t := table.(type) {
case *sqlparser.AliasedTableExpr:
fmt.Println("Table: ", sqlparser.String(t.Expr))
}
}
for _, expr := range update.Exprs {
fmt.Printf("Column: %s, New value: %s\n", expr.Name.Name, sqlparser.String(expr.Expr))
}
}