Skip to content

Commit

Permalink
Merge pull request #76 from opengisch/getnextsequence
Browse files Browse the repository at this point in the history
Function to get back the next sequence value
  • Loading branch information
signedav authored Nov 24, 2023
2 parents e452e29 + a02af09 commit 5ee9972
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions modelbaker/dbconnector/db_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ def get_ili2db_sequence_value(self):
"""
return None

def get_next_ili2db_sequence_value(self):
"""
Increases and returns the value of the sequence used for the t_id
"""
return None

def set_ili2db_sequence_value(self, value):
"""
Resets the current value of the sequence used for the t_id
Expand Down
8 changes: 8 additions & 0 deletions modelbaker/dbconnector/gpkg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,14 @@ def get_ili2db_sequence_value(self):
return content[0]
return None

def get_next_ili2db_sequence_value(self):
(
status,
next_id,
fetch_and_increment_feedback,
) = self._fetch_and_increment_key_object(self.tid)
return next_id

def set_ili2db_sequence_value(self, value):
if self._table_exists("T_KEY_OBJECT"):
try:
Expand Down
4 changes: 4 additions & 0 deletions modelbaker/dbconnector/mssql_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ def get_ili2db_settings(self):
return result

def get_ili2db_sequence_value(self):
# not implemented, return the next one
return self.get_next_ili2db_sequence_value()

def get_next_ili2db_sequence_value(self):
if self.schema:
cur = self.conn.cursor()
cur.execute(
Expand Down
16 changes: 16 additions & 0 deletions modelbaker/dbconnector/pg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,22 @@ def get_ili2db_sequence_value(self):
return content[0]
return None

def get_next_ili2db_sequence_value(self):

if self.schema:
cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute(
"""
SELECT nextval('{schema}.{sequence}')
""".format(
schema=self.schema, sequence="t_ili2db_seq"
)
)
content = cur.fetchone()
if content:
return content[0]
return None

def set_ili2db_sequence_value(self, value):
if self.schema:
cur = self.conn.cursor()
Expand Down
6 changes: 3 additions & 3 deletions modelbaker/iliwrapper/ili2dbtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ def get_tool_version(tool, db_ili_version):
if db_ili_version == 3:
return "3.11.3"
else:
return "5.0.0"
return "5.0.1"
elif tool == DbIliMode.ili2pg:
if db_ili_version == 3:
return "3.11.2"
else:
return "5.0.0"
return "5.0.1"
elif tool == DbIliMode.ili2mssql:
if db_ili_version == 3:
return "3.12.2"
else:
return "5.0.0"
return "5.0.1"

return "0"

Expand Down

0 comments on commit 5ee9972

Please sign in to comment.