Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
3a12e238
Commit
3a12e238
authored
Mar 10, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support oracle
parent
f45b271b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
1 deletion
+69
-1
db_alias.go
orm/db_alias.go
+2
-1
db_oracle.go
orm/db_oracle.go
+67
-0
No files found.
orm/db_alias.go
View file @
3a12e238
...
...
@@ -59,6 +59,7 @@ var (
"postgres"
:
DRPostgres
,
"sqlite3"
:
DRSqlite
,
"tidb"
:
DRTiDB
,
"oracle"
:
DROracle
,
}
dbBasers
=
map
[
DriverType
]
dbBaser
{
DRMySQL
:
newdbBaseMysql
(),
...
...
@@ -151,7 +152,7 @@ func detectTZ(al *alias) {
al
.
Engine
=
"INNODB"
}
case
DRSqlite
:
case
DRSqlite
,
DROracle
:
al
.
TZ
=
time
.
UTC
case
DRPostgres
:
...
...
orm/db_oracle.go
View file @
3a12e238
...
...
@@ -14,6 +14,41 @@
package
orm
import
(
"fmt"
"strings"
)
// oracle operators.
var
oracleOperators
=
map
[
string
]
string
{
"exact"
:
"= ?"
,
"gt"
:
"> ?"
,
"gte"
:
">= ?"
,
"lt"
:
"< ?"
,
"lte"
:
"<= ?"
,
"//iendswith"
:
"LIKE ?"
,
}
// oracle column field types.
var
oracleTypes
=
map
[
string
]
string
{
"pk"
:
"NOT NULL PRIMARY KEY"
,
"bool"
:
"bool"
,
"string"
:
"VARCHAR2(%d)"
,
"string-text"
:
"VARCHAR2(%d)"
,
"time.Time-date"
:
"DATE"
,
"time.Time"
:
"TIMESTAMP"
,
"int8"
:
"INTEGER"
,
"int16"
:
"INTEGER"
,
"int32"
:
"INTEGER"
,
"int64"
:
"INTEGER"
,
"uint8"
:
"INTEGER"
,
"uint16"
:
"INTEGER"
,
"uint32"
:
"INTEGER"
,
"uint64"
:
"INTEGER"
,
"float64"
:
"NUMBER"
,
"float64-decimal"
:
"NUMBER(%d, %d)"
,
}
// oracle dbBaser
type
dbBaseOracle
struct
{
dbBase
...
...
@@ -27,3 +62,35 @@ func newdbBaseOracle() dbBaser {
b
.
ins
=
b
return
b
}
// OperatorSQL get oracle operator.
func
(
d
*
dbBaseOracle
)
OperatorSQL
(
operator
string
)
string
{
return
oracleOperators
[
operator
]
}
// DbTypes get oracle table field types.
func
(
d
*
dbBaseOracle
)
DbTypes
()
map
[
string
]
string
{
return
oracleTypes
}
//ShowTablesQuery show all the tables in database
func
(
d
*
dbBaseOracle
)
ShowTablesQuery
()
string
{
return
"SELECT TABLE_NAME FROM USER_TABLES"
}
// Oracle
func
(
d
*
dbBaseOracle
)
ShowColumnsQuery
(
table
string
)
string
{
return
fmt
.
Sprintf
(
"SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS "
+
"WHERE TABLE_NAME ='%s'"
,
strings
.
ToUpper
(
table
))
}
// check index is exist
func
(
d
*
dbBaseOracle
)
IndexExists
(
db
dbQuerier
,
table
string
,
name
string
)
bool
{
row
:=
db
.
QueryRow
(
"SELECT COUNT(*) FROM USER_IND_COLUMNS, USER_INDEXES "
+
"WHERE USER_IND_COLUMNS.INDEX_NAME = USER_INDEXES.INDEX_NAME "
+
"AND USER_IND_COLUMNS.TABLE_NAME = ? AND USER_IND_COLUMNS.INDEX_NAME = ?"
,
strings
.
ToUpper
(
table
),
strings
.
ToUpper
(
name
))
var
cnt
int
row
.
Scan
(
&
cnt
)
return
cnt
>
0
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment