Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Merge requests
!134
Load and execute sql script from file
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Load and execute sql script from file
dk-sql-script-executor
into
develop
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Dariusz Kędzierski
requested to merge
dk-sql-script-executor
into
develop
4 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
567aab48
1 commit,
4 years ago
1 file
+
24
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
hive/db/schema.py
+
24
−
0
Options
@@ -1741,3 +1741,27 @@ def set_logged_table_attribute(db, logged):
log
.
info
(
"
Setting {} attribute on a table: {}
"
.
format
(
'
LOGGED
'
if
logged
else
'
UNLOGGED
'
,
table
))
sql
=
"""
ALTER TABLE {} SET {}
"""
db
.
query_no_return
(
sql
.
format
(
table
,
'
LOGGED
'
if
logged
else
'
UNLOGGED
'
))
def
execute_sql_script
(
query_executor
,
path_to_script
):
"""
Load and execute sql script from file
Params:
query_executor - callable to execute query with
path_to_script - path to script
Returns:
depending on query_executor
Example:
print(execute_sql_script(db.query_row,
"
./test.sql
"
))
where test_sql: SELECT * FROM hive_state WHERE block_num = 0;
will return something like: (0, 18, Decimal(
'
0.000000
'
), Decimal(
'
0.000000
'
), Decimal(
'
0.000000
'
),
''
)
"""
try
:
sql_script
=
None
with
open
(
path_to_script
,
'
r
'
)
as
sql_script_file
:
sql_script
=
sql_script_file
.
read
()
if
sql_script
is
not
None
:
return
query_executor
(
sql_script
)
except
Exception
as
ex
:
log
.
exception
(
"
Error running sql script: {}
"
.
format
(
ex
))
raise
ex
return
None
\ No newline at end of file
Loading