Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Use quote_ident() for database names in queries #395

Merged
merged 1 commit into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,15 @@ def create_database(self, dbname):
:param dbname: the name of the database to create
:type dbname: str
"""
self.query("CREATE DATABASE \"%s\"" % dbname)
self.query("CREATE DATABASE {0}".format(quote_ident(dbname)))

def drop_database(self, dbname):
"""Drop a database from InfluxDB.

:param dbname: the name of the database to drop
:type dbname: str
"""
self.query("DROP DATABASE \"%s\"" % dbname)
self.query("DROP DATABASE {0}".format(quote_ident(dbname)))

def create_retention_policy(self, name, duration, replication,
database=None, default=False):
Expand All @@ -517,9 +517,10 @@ def create_retention_policy(self, name, duration, replication,
:type default: bool
"""
query_string = \
"CREATE RETENTION POLICY \"%s\" ON \"%s\" " \
"DURATION %s REPLICATION %s" % \
(name, database or self._database, duration, replication)
"CREATE RETENTION POLICY {0} ON {1} " \
"DURATION {2} REPLICATION {3}".format(
quote_ident(name), quote_ident(database or self._database),
duration, replication)

if default is True:
query_string += " DEFAULT"
Expand Down Expand Up @@ -597,8 +598,15 @@ def get_list_retention_policies(self, database=None):
u'name': u'default',
u'replicaN': 1}]
"""

if not (database or self._database):
raise InfluxDBClientError(
"get_list_retention_policies() requires a database as a "
"parameter or the client to be using a database")

rsp = self.query(
"SHOW RETENTION POLICIES ON \"%s\"" % (database or self._database)
"SHOW RETENTION POLICIES ON {0}".format(
quote_ident(database or self._database))
)
return list(rsp.get_points())

Expand Down
2 changes: 1 addition & 1 deletion influxdb/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def test_get_list_retention_policies(self):
text=example_response
)
self.assertListEqual(
self.cli.get_list_retention_policies(),
self.cli.get_list_retention_policies("db"),
[{'duration': '24h0m0s',
'name': 'fsfdsdf', 'replicaN': 2}]
)
Expand Down