albfernandez / javadbf

Java library for reading and writing Xbase (dBase/DBF) files.
GNU Lesser General Public License v3.0
224 stars 98 forks source link

No support for writting TIMESTAMP #111

Closed hectorsipe closed 1 year ago

hectorsipe commented 1 year ago

Hi, I'm gettig this error:

java.lang.IllegalArgumentException: No support for writting TIMESTAMP at com.linuxense.javadbf.DBFField.setType(DBFField.java:431)

I guess it's not implemented yet, but is there an alternative to avoid it?

sumenkov commented 1 year ago

Hi! Convert timestamp to date in Java Let's see the simple example to convert Timestamp to Date in java.

import java.sql.Timestamp;
import java.util.Date;

public class TimestampToDateExample1 {

    public static void main(String args[]) {

        Timestamp ts = new Timestamp(System.currentTimeMillis());
        Date date = new Date(ts.getTime());

        System.out.println(date);
    }
}
sumenkov commented 1 year ago

Supported types for reading and writing DBF

XBase Type | XBase Symbol | Java Type used in JavaDBF | Write Supported -- | -- | -- | -- Character | C | java.lang.String | True Numeric | N | java.math.BigDecimal | True Floating Point | F | java.math.BigDecimal | True Logical | L | java.lang.Boolean | True Date | D | java.util.Date | True Currency | Y | java.math.BigDecimal | False Long | I | java.lang.Integer | False Date Type | T | java.util.Date | False Timestamp | @ | java.util.Date | False AutoIncrement | + | java.lang.Integer | False Memo | M | java.lang.String or byte[] | False Binary | B | byte[] or java.lang.Double | False Blob | W | byte[] | False General | G | byte[] | False Picture | P | byte[] | False VarBinary | Q | byte[] | False Varchar | V | java.lang.String | False Double | O | java.lang.Double | False
raidenmaister commented 1 year ago

Incredible @sumenkov 👌

Tixbert commented 1 year ago

Hi,

we have a very old .dbf database and want to use JavaDBF to write new records to the database. The database has an field with the type "DATETIME". This is not supported in JavaDBF as far as I understand. The field has no real function and is empty in most cases. But we cannot alter the type or remove the field because of other programs accessing the database.

Is there a way to just skip the field while adding a record to the database?

Thanks in advance

Florian

sumenkov commented 1 year ago

Hi,

we have a very old .dbf database and want to use JavaDBF to write new records to the database. The database has an field with the type "DATETIME". This is not supported in JavaDBF as far as I understand. The field has no real function and is empty in most cases. But we cannot alter the type or remove the field because of other programs accessing the database.

Is there a way to just skip the field while adding a record to the database?

Thanks in advance

Florian

the first thing that comes to mind is to just give this field the value NULL be sure to send us the result

Tixbert commented 1 year ago

Thanks for the quick reply. Sadly its not working. We get the following errors:

The field with the DATETIME Type in the database is called "ERFDATUM"

Java Object ERFDATUM defined as String and just keep the string empty

DBFException: Unsupported writting of field type 14 TIMESTAMP com.linuxense.javadbf.DBFWriter.addRecord(DBFWriter.java:289)

 

Empty String as null

DBFException: Unknown field type TIMESTAMP com.linuxense.javadbf.DBFWriter.writeRecord(DBFWriter.java:424) com.linuxense.javadbf.DBFWriter.addRecord(DBFWriter.java:298)

 

Java Object ERFDATUM defined as Date Date as null

DBFException: Unknown field type TIMESTAMP com.linuxense.javadbf.DBFWriter.writeRecord(DBFWriter.java:424) com.linuxense.javadbf.DBFWriter.addRecord(DBFWriter.java:298)

Wer have found the following explanation for "null" not working:

We are in the 'DBFWriter.java' class:

With addRecord() a check of the value to null takes place in the for loop. If the value is null it continues the next field. But in the method writeRecord() the value is no longer checked for null, so that in the default block the DBFException Unknown field type is thrown.

Is there a way to bypass or repair this?  

sumenkov commented 1 year ago

DBFException: Unknown field type TIMESTAMP

here is the answer ) on this type I commented above

sumenkov commented 1 year ago

Unfortunately, I have no way to test with such a file. if it's not a secret, send it to my mail, this will give me the opportunity to test, not guess ) sumenkov.dv@gmail.com

Tixbert commented 1 year ago

I´ve send you a small version of our database. If there is a workaround to add a record without altering the field type of "ERFDATUM" we would be very happy.

sumenkov commented 1 year ago

I´ve send you a small version of our database.

Hello! I received the file, I will answer as soon as I can do the tests)

sumenkov commented 1 year ago

I´ve send you a small version of our database. If there is a workaround to add a record without altering the field type of "ERFDATUM" we would be very happy.

To my regret, without the author it is impossible to help. I have one solution, send it to the mail. But of course this is not what it should be.

albfernandez commented 1 year ago

Hi javadbf currently cannot write dbf7 files (that includes TIMESTAMP types and many others) There is a lot of work to do (new headers and register formats, null management, new data types) in writer and "sync mode" I'll work on it when I have the time. help is always welcome.

Tixbert commented 1 year ago

Hi, thanks for the reply. So we will search for a different solution.