Skip to content

Commit

Permalink
Merge pull request #501 from Jiang-Hua/use_db2tcl_drop_schema
Browse files Browse the repository at this point in the history
Use db2tcl to create and drop database for DB2
  • Loading branch information
abondvt89 committed Feb 9, 2023
2 parents fc63f7f + 99b3f97 commit 6be0f62
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
38 changes: 21 additions & 17 deletions src/db2/db2olap.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ proc ConnectToDb2 { dbname user password } {
return $db_handle
}}

proc CreateDatabase { dbname } {
puts "CREATING DATABASE $dbname"
if {[ catch {db2_create_db $dbname} message ]} {
error $message
} else {
puts "DATABASE $dbname has been created successfully."
}

return
}

proc CreateTables { db_handle tspace organization } {
puts "CREATING TPCH TABLES"
if { $organization eq "DATE" } {
Expand Down Expand Up @@ -494,6 +505,7 @@ proc do_tpch { dbname scale_fact user password tpch_def_tab column_based num_vu
}
if { $threaded eq "SINGLE-THREADED" || $threaded eq "MULTI-THREADED" && $myposition eq 1 } {
puts "CREATING [ string toupper $user ] SCHEMA"
CreateDatabase $dbname
set db_handle [ ConnectToDb2 $dbname $user $password ]
switch [ string toupper $column_based ] {
COLUMN { set organization "organize by column" }
Expand Down Expand Up @@ -1184,30 +1196,22 @@ set library $library
if [catch {::tcl::tm::path add modules} ] { error "Failed to find modules directory" }
if [catch {package require tpchcommon} ] { error "Failed to load tpch common functions" } else { namespace import tpchcommon::* }

proc drop_schema { dbname user password } {
global tcl_platform
set force "db2 force applications all"
set drop "db2 drop database $dbname"
if {$tcl_platform(platform) == "windows"} {
set prefix "db2cmd -c"
} else {
set prefix ""
}

if {[ catch {eval exec [ concat $prefix $force ]} message ]} {
proc drop_schema { dbname } {
if {[ catch {db2_force_off} message ]} {
error $message
} else {
puts "force applications all complete."
if {[ catch {eval exec [ concat $prefix $drop ]} message ]} {
error $message
} else {
puts "$dbname TPROC-H schema has been deleted successfully."
if {[ catch {db2_drop_db $dbname} message ]} {
error $message
} else {
puts "$dbname TPROC-H schema has been deleted successfully."
}
}
}

return
}
}
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end "drop_schema $db2_tpch_dbase $db2_tpch_user $db2_tpch_pass"
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end "drop_schema $db2_tpch_dbase"
} else { return }
}

38 changes: 21 additions & 17 deletions src/db2/db2oltp.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,17 @@ proc ConnectToDb2 { dbname user password } {
return $db_handle
}}

proc CreateDatabase { dbname } {
puts "CREATING DATABASE $dbname"
if {[ catch {db2_create_db $dbname} message ]} {
error $message
} else {
puts "DATABASE $dbname has been created successfully."
}

return
}

proc CreateTables { db_handle num_part count_ware tspace_dict } {
puts "CREATING TPCC TABLES"
set sql(2) "CREATE TABLE DISTRICT (D_NEXT_O_ID INTEGER, D_TAX REAL, D_YTD DECIMAL(12, 2), D_NAME CHAR(10), D_STREET_1 CHAR(20), D_STREET_2 CHAR(20), D_CITY CHAR(20), D_STATE CHAR(2), D_ZIP CHAR(9), D_ID SMALLINT NOT NULL, D_W_ID INTEGER NOT NULL) IN [ dict get $tspace_dict D ] INDEX IN [ dict get $tspace_dict D ] ORGANIZE BY KEY SEQUENCE ( D_ID STARTING FROM 1 ENDING AT 10, D_W_ID STARTING FROM 1 ENDING AT $count_ware ) ALLOW OVERFLOW"
Expand Down Expand Up @@ -846,6 +857,7 @@ proc do_tpcc { dbname user password count_ware partition num_vu tpcc_def_tab tpc
set num_vu 1
}
if { $threaded eq "SINGLE-THREADED" || $threaded eq "MULTI-THREADED" && $myposition eq 1 } {
CreateDatabase $dbname
set db_handle [ ConnectToDb2 $dbname $user $password ]
if { $partition eq "true" && [ expr $count_ware >= 10 ] } {
set num_part 10
Expand Down Expand Up @@ -2334,29 +2346,21 @@ set library $library
if [catch {::tcl::tm::path add modules} ] { error "Failed to find modules directory" }
if [catch {package require tpcccommon} ] { error "Failed to load tpcc common functions" } else { namespace import tpcccommon::* }

proc drop_schema { dbname user password } {
global tcl_platform
set force "db2 force applications all"
set drop "db2 drop database $dbname"
if {$tcl_platform(platform) == "windows"} {
set prefix "db2cmd -c"
} else {
set prefix ""
}

if {[ catch {eval exec [ concat $prefix $force ]} message ]} {
proc drop_schema { dbname } {
if {[ catch {db2_force_off} message ]} {
error $message
} else {
puts "force applications all complete."
if {[ catch {eval exec [ concat $prefix $drop ]} message ]} {
error $message
} else {
puts "$dbname TPROC-C schema has been deleted successfully."
if {[ catch {db2_drop_db $dbname} message ]} {
error $message
} else {
puts "$dbname TPROC-C schema has been deleted successfully."
}
}
}

return
}
}
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end "drop_schema $db2_dbase $db2_user $db2_pass"
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end "drop_schema $db2_dbase"
} else { return }
}

0 comments on commit 6be0f62

Please sign in to comment.