Giter Club home page Giter Club logo

rd-lib-jdbacl's People

Contributors

ake2l avatar dangsg avatar deepsourcebot avatar peterbrinkhoff avatar thetacchg avatar vbergmann2 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

rd-lib-jdbacl's Issues

Multischema: table with same name in different schema with different named key columns

If you have a table with same name in different schema with different named key columns you will get an error while importing jdbc model and won't be able to use benerator for this database structure with includeTables="#all"

  • rework of jdbc validation model will happen in 1.2.0
  • there will be a patch soon in form of additional filter tag like #allkeys and #alltable to keep it more flexible until a proper solution will be there

Hotfix

in multischema mode with includeTables="#all" the mechanism to import pkeys into Object model did not work properly, the query filter was wrong, i removed the schema and catalog filter criteria and import all matching dbtable pkeys from pg_catalog now.

if (this.tableInclusionPattern != null && this.tableInclusionPattern.contains("#all")) {
  // removed filter catalog and schema to get all primary keys for matching tables
  pkset = metaData.getPrimaryKeys(null, null, table.getName());
} else {
  pkset = metaData.getPrimaryKeys(catalogName, schemaName, table.getName());
}

the query result looks ...

SELECT result.TABLE_CAT, result.TABLE_SCHEM, result.TABLE_NAME, result.COLUMN_NAME, result.KEY_SEQ, result.PK_NAME
FROM (SELECT NULL                                             AS TABLE_CAT,
             n.nspname                                        AS TABLE_SCHEM,
             ct.relname                                       AS TABLE_NAME,
             a.attname                                        AS COLUMN_NAME,
             (information_schema._pg_expandarray(i.indkey)).n AS KEY_SEQ,
             ci.relname                                       AS PK_NAME,
             information_schema._pg_expandarray(i.indkey)     AS KEYS,
             a.attnum                                         AS A_ATTNUM
      FROM pg_catalog.pg_class ct
               JOIN pg_catalog.pg_attribute a ON (ct.oid = a.attrelid)
               JOIN pg_catalog.pg_namespace n ON (ct.relnamespace = n.oid)
               JOIN pg_catalog.pg_index i ON (a.attrelid = i.indrelid)
               JOIN pg_catalog.pg_class ci ON (ci.oid = i.indexrelid)
      WHERE true
        AND n.nspname = 'schema1'
        AND ct.relname = 'db_role'
        AND i.indisprimary) result
where result.A_ATTNUM = (result.KEYS).x
ORDER BY result.table_name, result.pk_name, result.key_seq

this check is executed for every datasource once but it results in on object model.
AND n.nspname = 'schema1' this is related only to the actual scope of datasource , but it should be not part of the filter when importing the whole database with references.

Postgres: error when using sequence on postgres 10+

Describe the bug

This issue originates from rapiddweller/rapiddweller-benerator-ce#134

I'm using postgres 10.1

When generating data using a postgres sequence (with DBSequenceGenerator), I get the following error:

java.lang.RuntimeException: Error executing query: select sequence_name, start_value, increment_by, max_value, min_value, is_cycled, cache_value, last_value from accounts_id_seq
    at com.rapiddweller.jdbacl.DBUtil.executeQuery (DBUtil.java:1014)
    at com.rapiddweller.jdbacl.DBUtil.querySingleRow (DBUtil.java:946)
    at com.rapiddweller.jdbacl.dialect.PostgreSQLDialect.querySequences (PostgreSQLDialect.java:93)
Caused by: org.postgresql.util.PSQLException: ERROR: column "sequence_name" does not exist
  Position: 8

It seems that sequence handling has been changed in postgres 10+

See rails/rails#28864

To Reproduce

  • start en empty postgres db
  • run this benerator.xml
<?xml version="1.0" encoding="UTF-8"?>

<setup xmlns="https://www.benerator.de/schema/2.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="https://www.benerator.de/schema/2.0.0-jdk-11 benerator-2.0.0.xsd"
        defaultEncoding="UTF-8"
        defaultDataset="US"
        defaultLocale="en_US"
        defaultLineSeparator="\n">

    <import platforms="db"/>

    <echo>
        Populates a database
    </echo>

    <echo>defining a database that will be referred by the id 'db' later</echo>
    <database id="db"
        url="jdbc:postgresql://localhost:5432/postgres"
        driver="org.postgresql.Driver"
        schema="public"
        user="postgres"
        password="postgres"/>


    <echo>Drop the testtable if it already exist. If it does not exist yet, the error message is ignored</echo>
    <execute target="db" type="sql" onError="ignore">
        DROP SEQUENCE IF EXISTS accounts_id_seq;
        DROP TABLE IF EXISTS accounts;
    </execute>

    <echo>Creating testtable</echo>
    <execute target="db" type="sql">
        CREATE SEQUENCE accounts_id_seq;
        CREATE TABLE accounts (
        user_id BIGINT PRIMARY KEY,
        username VARCHAR ( 50 ) UNIQUE NOT NULL
        );
    </execute>

    <echo>Generating 100 entries for testtable</echo>
    <generate type="accounts" consumer="db,ConsoleExporter" count="100">
        <id name="id" type="long"
            generator="new DBSequenceGenerator('accounts_id_seq', db, true)"/>
    </generate>
</setup>

Full project is available here: https://github.com/gonzalad/benerator-postgresql/tree/issue-postgres-sequence

Expected behavior

Data generation with a sequence should work.

Versions:

  • benerator: 2.0.0-jdk-11
  • postgres: 10.1 (but we should have the same error in 10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.