Get CockroachDB version from the connection info

This commit is contained in:
Daniele Varrazzo 2020-07-21 21:48:11 +01:00
parent 7e1e801899
commit 9380f2a721

View File

@ -424,20 +424,17 @@ def crdb_version(conn, __crdb_version=[]):
if __crdb_version: if __crdb_version:
return __crdb_version[0] return __crdb_version[0]
with conn.cursor() as cur: sver = conn.info.parameter_status("crdb_version")
try: if sver is None:
cur.execute("show crdb_version") __crdb_version.append(None)
except psycopg2.ProgrammingError: else:
__crdb_version.append(None) m = re.search(r"\bv(\d+)\.(\d+)\.(\d+)", sver)
else: if not m:
sver = cur.fetchone()[0] raise ValueError(
m = re.search(r"\bv(\d+)\.(\d+)\.(\d+)", sver) "can't parse CockroachDB version from %s" % sver)
if not m:
raise ValueError(
"can't parse CockroachDB version from %s" % sver)
ver = int(m.group(1)) * 10000 + int(m.group(2)) * 100 + int(m.group(3)) ver = int(m.group(1)) * 10000 + int(m.group(2)) * 100 + int(m.group(3))
__crdb_version.append(ver) __crdb_version.append(ver)
return __crdb_version[0] return __crdb_version[0]