Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Datenbank anonymisierung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Volland
Datenbank anonymisierung
Commits
e7ef0ba9
Commit
e7ef0ba9
authored
5 years ago
by
Julian Volland
Browse files
Options
Downloads
Patches
Plain Diff
changed name
parent
2a98edf6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyargdatatotable.py
+0
-53
0 additions, 53 deletions
pyargdatatotable.py
with
0 additions
and
53 deletions
pyargdatatotable.py
deleted
100755 → 0
+
0
−
53
View file @
2a98edf6
#!/usr/bin/env python3
import
psycopg2
from
psycopg2
import
sql
import
sys
import
argparse
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
-f
'
,
'
--file
'
,
required
=
True
,
help
=
"
Filelocation
"
)
parser
.
add_argument
(
'
-t
'
,
'
--tablename
'
,
required
=
True
,
help
=
"
Tablename
"
)
parser
.
add_argument
(
'
-n
'
,
'
--name
'
,
required
=
True
,
help
=
"
Databasename
"
)
parser
.
add_argument
(
'
-u
'
,
'
--user
'
,
required
=
True
,
help
=
"
Databaseuser
"
)
parser
.
add_argument
(
'
-p
'
,
'
--password
'
,
required
=
False
,
help
=
"
userpassword
"
)
parser
.
add_argument
(
'
-s
'
,
'
--schema
'
,
required
=
True
,
help
=
"
Schema
"
)
args
=
parser
.
parse_args
()
filelocation
=
args
.
file
tablename
=
args
.
tablename
databasename
=
args
.
name
databaseuser
=
args
.
user
userpassword
=
args
.
password
schema
=
args
.
schema
if
userpassword
==
None
:
connectionstring
=
(
"
dbname=
"
+
databasename
+
"
user=
"
+
databaseuser
)
else
:
connectionstring
=
(
"
dbname=
"
+
databasename
+
"
user=
"
+
databaseuser
+
"
password=
"
+
userpassword
)
conn
=
psycopg2
.
connect
(
connectionstring
)
cur
=
conn
.
cursor
()
file
=
open
(
filelocation
,
"
rt
"
)
lines
=
file
.
readlines
()
file
.
close
()
try
:
cur
.
execute
(
sql
.
SQL
(
"
DROP TABLE {}
"
).
format
(
sql
.
Identifier
(
tablename
)))
except
:
conn
.
rollback
()
finally
:
cur
.
execute
(
sql
.
SQL
(
"
CREATE TABLE {} (id serial PRIMARY KEY, {} varchar)
"
).
format
(
sql
.
Identifier
(
tablename
),
sql
.
Identifier
(
tablename
)))
for
name
in
lines
:
cur
.
execute
(
sql
.
SQL
(
"
INSERT INTO {}.{} ({}) VALUES (%s)
"
).
format
(
sql
.
Identifier
(
schema
),
sql
.
Identifier
(
tablename
),
sql
.
Identifier
(
tablename
)),(
name
[:
-
1
],
))
conn
.
commit
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment