Skip to content

Commit 15210d1

Browse files
committed
Use quote_ident() to allow databases with spaces in the names
* Added an exception when the paramters will create a malformed request. * Updated the tests around this to use a named databse instead.
1 parent f9bd6cc commit 15210d1

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

influxdb/client.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,15 @@ def create_database(self, dbname):
485485
:param dbname: the name of the database to create
486486
:type dbname: str
487487
"""
488-
self.query("CREATE DATABASE \"%s\"" % dbname)
488+
self.query("CREATE DATABASE {0}".format(quote_ident(dbname)))
489489

490490
def drop_database(self, dbname):
491491
"""Drop a database from InfluxDB.
492492
493493
:param dbname: the name of the database to drop
494494
:type dbname: str
495495
"""
496-
self.query("DROP DATABASE \"%s\"" % dbname)
496+
self.query("DROP DATABASE {0}".format(quote_ident(dbname)))
497497

498498
def create_retention_policy(self, name, duration, replication,
499499
database=None, default=False):
@@ -517,9 +517,10 @@ def create_retention_policy(self, name, duration, replication,
517517
:type default: bool
518518
"""
519519
query_string = \
520-
"CREATE RETENTION POLICY \"%s\" ON \"%s\" " \
521-
"DURATION %s REPLICATION %s" % \
522-
(name, database or self._database, duration, replication)
520+
"CREATE RETENTION POLICY {0} ON {1} " \
521+
"DURATION {2} REPLICATION {3}".format(
522+
quote_ident(name), quote_ident(database or self._database),
523+
duration, replication)
523524

524525
if default is True:
525526
query_string += " DEFAULT"
@@ -597,8 +598,15 @@ def get_list_retention_policies(self, database=None):
597598
u'name': u'default',
598599
u'replicaN': 1}]
599600
"""
601+
602+
if not (database or self._database):
603+
raise InfluxDBClientError(
604+
"get_list_retention_policies() requires a database as a "
605+
"parameter or the client to be using a database")
606+
600607
rsp = self.query(
601-
"SHOW RETENTION POLICIES ON \"%s\"" % (database or self._database)
608+
"SHOW RETENTION POLICIES ON {0}".format(
609+
quote_ident(database or self._database))
602610
)
603611
return list(rsp.get_points())
604612

influxdb/tests/client_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def test_get_list_retention_policies(self):
591591
text=example_response
592592
)
593593
self.assertListEqual(
594-
self.cli.get_list_retention_policies(),
594+
self.cli.get_list_retention_policies("db"),
595595
[{'duration': '24h0m0s',
596596
'name': 'fsfdsdf', 'replicaN': 2}]
597597
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy