Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after reload old data returns #14

Open
tim08 opened this issue Nov 27, 2024 · 7 comments
Open

after reload old data returns #14

tim08 opened this issue Nov 27, 2024 · 7 comments

Comments

@tim08
Copy link

tim08 commented Nov 27, 2024

my dependencies:

        <dependency>
            <artifactId>dbschema-dbf-jdbc</artifactId>
            <groupId>dbschema-dbf-jdbc</groupId>
            <scope>system</scope>
            <version>1.1</version>
            <systemPath>${project.basedir}/lib/dbschema-dbf-jdbc1.1.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.github.albfernandez</groupId>
            <artifactId>javadbf</artifactId>
            <version>1.14.1</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>2.2.224</version>
        </dependency>

if i use

        <dependency>
                <groupId>com.wisecoders</groupId>
                <artifactId>dbf-jdbc-driver</artifactId>
                <version>1.1.2</version>
        </dependency>

I get an error

Exception in thread "main" org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "file_name" not found
Column "file_name" not found; SQL statement:
DELETE FROM dbs_meta_files WHERE file_name=? [42122-224]

my code(I wrote it to reproduce the problem - in fact, I use the library in combination camel+karaf)

    public static void main(String[] args) throws SQLException, InterruptedException {

        String URL = "jdbc:dbschema:dbf:c:\\tmp\\sample\\";

        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;

        int ii = 0;
        do {
            Thread.sleep(2000);
            System.out.println(ii);
            ii++;
            try{
                new com.wisecoders.dbschema.dbf.JdbcDriver();
                conn = DriverManager.getConnection(URL);
                st = conn.createStatement();
             st.execute("reload c:\\tmp\\sample\\sample.dbf");

                JSONArray jsonArray = new JSONArray();
                
                if (st.execute("select * from sample limit 1")) {
                    rs = st.getResultSet();

                    while (rs.next()) {

                        int columns = rs.getMetaData().getColumnCount();
                        JSONObject obj = new JSONObject();

                        for (int i = 0; i < columns; i++)
                            obj.put(rs.getMetaData().getColumnLabel(i + 1).toLowerCase(), rs.getObject(i + 1));

                        jsonArray.put(obj);
                    }
                }
                System.out.println(jsonArray);

            }finally {
                try { rs.close(); } catch (Exception e) { /* Ignored */ }
                try { st.close(); } catch (Exception e) { /* Ignored */ }
                try { conn.close(); } catch (Exception e) { /* Ignored */ }
            }
        }
        while (ii < 100);

    }

at a certain point in time it is replaced by a new file c:\tmp\sample\sample.dbf , but at the next iteration I see old data despite the method call st.execute("reload ...

ps: if i delete a folder /.DbSchema/

Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.GeneratedMethodAccessor467.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.wisecoders.dbschema.dbf.H2Connection$StatementProxy.invoke(H2Connection.java:105)
	... 41 more
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "sample" not found (this database is empty); SQL statement:
select * from sample [42104-224]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
	at org.h2.message.DbException.get(DbException.java:223)
	at org.h2.message.DbException.get(DbException.java:199)
	at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8051)
	at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8035)
@dbschema-pro
Copy link
Owner

I checked the code and the current version is using file_path and not file_name. So we released a new driver, version 1.2 and published it. Please give this a try.

@tim08
Copy link
Author

tim08 commented Nov 28, 2024

are you suggesting we use com.wisecoders/dbf-jdbc-driver/1.1.2 ? If yes, I wrote about it above (the error Column ‘file_name’ not found is reproduced on it). I don't quite understand what is the difference between dbf-jdbc-driver and dbschema-dbf-jdbc

@dbschema-pro
Copy link
Owner

The 'dbschema-dbf-jdbc' was wrong. Was used in the jar task, in build.gradle. We replaced it with dbf-jdbc-driver and published again as version 1.3

@tim08
Copy link
Author

tim08 commented Nov 28, 2024

I rebuild version 1.3 after your fixes, I also checked that the record in the dbs_meta_files table is indeed deleted after calling ‘reload’, but I still get the old data
What's the logic behind the ‘reload’ method? I assumed it was supposed to call something like:
https://github.com/wise-coders/dbf-jdbc-driver/blob/master/src/main/java/com/wisecoders/dbschema/dbf/JdbcDriver.java#L112

ps: I get new data from the dbf-file only after restarting app(jvm)

@dbschema-pro
Copy link
Owner

The reload is more or less for cleaning the caches and reloading the file. Probably it is a bug somewhere if the data is still in H2. If you confirm this we can start to research.

@dbschema-pro dbschema-pro reopened this Nov 28, 2024
@tim08
Copy link
Author

tim08 commented Dec 3, 2024

the ‘reload’ method works normally only after the application is restarted, if you try to update the data while the application is running(in the same connection) you will get old data, If you use a connection pool (like dbcp2), the update will not occur even on new connections.
problem reproduction algorithm:

  • st.execute("select * from sample limit 1")
  • the dbf-file in the directory is changed to a new one
  • st.execute("reload directory");
  • st.execute("select * from sample limit 1")
    in step 4, I get the old data

my current fix "reload":

        private void reload( String filePath ) throws Exception {
        try (PreparedStatement st = h2Connection.prepareStatement("DELETE FROM " + FILES_META_TABLE + " WHERE file_path=?")) {
            st.setString(1, filePath);
            st.executeUpdate();
        }
        final File folder = (new File(filePath)).getParentFile();

        if (!folder.exists()) {
            throw new SQLException("Folder does not exists: '" + folder + "'");
        }
        if (!folder.isDirectory()) {
            throw new SQLException("Expected path is not folder: '" + folder + "'");
        }
        transferFolder(folder, folder, this.h2Connection, null);
    }

@dbschema-pro
Copy link
Owner

Thank you for sending the fix. We included it in the current JDBC driver, and uploaded a new version of the driver on our website

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants