Skip to content

Commit

Permalink
[jdbc] Select the proper schema when retrieving the item tables (open…
Browse files Browse the repository at this point in the history
…hab#11023)

Signed-off-by: Riccardo Nimser-Joseph <[email protected]>
  • Loading branch information
nimric authored Jul 24, 2021
1 parent e23a0de commit cf6729a
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ private void initSqlQueries() {
sqlIfTableExists = "SELECT * FROM PG_TABLES WHERE TABLENAME='#searchTable#'";
sqlCreateItemsTableIfNot = "CREATE TABLE IF NOT EXISTS #itemsManageTable# (itemid SERIAL NOT NULL, #colname# #coltype# NOT NULL, CONSTRAINT #itemsManageTable#_pkey PRIMARY KEY (itemid))";
sqlCreateNewEntryInItemsTable = "INSERT INTO items (itemname) SELECT itemname FROM #itemsManageTable# UNION VALUES ('#itemname#') EXCEPT SELECT itemname FROM items";
sqlGetItemTables = "SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema='public' AND NOT table_name='#itemsManageTable#'";
sqlGetItemTables = "SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema=(SELECT table_schema "
+ "FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_name='#itemsManageTable#') AND NOT table_name='#itemsManageTable#'";
// http://stackoverflow.com/questions/17267417/how-do-i-do-an-upsert-merge-insert-on-duplicate-update-in-postgresql
// for later use, PostgreSql > 9.5 to prevent PRIMARY key violation use:
// SQL_INSERT_ITEM_VALUE = "INSERT INTO #tableName# (TIME, VALUE) VALUES( NOW(), CAST( ? as #dbType#) ) ON
Expand Down Expand Up @@ -121,9 +122,10 @@ public Long doCreateNewEntryInItemsTable(ItemsVO vo) {

@Override
public List<ItemsVO> doGetItemTables(ItemsVO vo) {
String sql = StringUtilsExt.replaceArrayMerge(sqlGetItemTables, new String[] { "#itemsManageTable#" },
new String[] { vo.getItemsManageTable() });
logger.debug("JDBC::doGetItemTables sql={}", sql);
String sql = StringUtilsExt.replaceArrayMerge(this.sqlGetItemTables,
new String[] { "#itemsManageTable#", "#itemsManageTable#" },
new String[] { vo.getItemsManageTable(), vo.getItemsManageTable() });
this.logger.debug("JDBC::doGetItemTables sql={}", sql);
return Yank.queryBeanList(sql, ItemsVO.class, null);
}

Expand Down

0 comments on commit cf6729a

Please sign in to comment.