We have a strange problem happening here, if We execute the following command using the last version available o HXTT
SELECT sum(F8)/sum(F5) as VAL, f4 FROM tablex WHERE F4 = 'ROGER VARGAS' group by f4
We get the following response
1.0303073128547828
With the following command (same but without the group by)
SELECT sum(F8)/sum(F5) as VAL FROM tablex WHERE F4 = 'ROGER VARGAS'
We get the following result
1.03
The precision of the division was lost !
The structure of the DBF is
F4 Character 20 Asc Machine Yes
F5 Numeric 15 2 Yes
F8 Numeric 12 2 Yes
You can see the problem running the following code
package javaapplication1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
public class RoundError {
public static void execute(String label, Connection con, String sql) throws SQLException, ParseException {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
System.out.println("\n"+label+"\n--------------------------------------------------------------");
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
System.out.print(rs.getMetaData().getColumnName(i + 1) + "(" + rs.getMetaData().getColumnTypeName(i + 1) + ")\t");
}
System.out.println("\n--------------------------------------------------------------");
while (rs.next()) {
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
System.out.print(rs.getObject(i+1)+"\t");
}
System.out.println("");
}
System.out.println("--------------------------------------------------------------");
stmt.close();
}
public static void main(String[] args) throws Exception {
String connectionUrl;
Connection con;
connectionUrl = "jdbc:DBF:/C:/temp";
Class.forName("com.hxtt.sql.dbf.DBFDriver");
con = DriverManager.getConnection(connectionUrl);
String sql = "SELECT sum(F8)/sum(F5) as VAL FROM tablex WHERE F4 = 'ROGER VARGAS'";
execute("without group by", con, sql);
sql = "SELECT sum(F8)/sum(F5) as VAL, f4 FROM tablex WHERE F4 = 'ROGER VARGAS' group by f4";
execute("with group by", con, sql);
con.close();
}
}
The result is
without group by
--------------------------------------------------------------
VAL(DOUBLE)
--------------------------------------------------------------
1.03
--------------------------------------------------------------
with group by
--------------------------------------------------------------
VAL(DOUBLE) F4(VARCHAR)
--------------------------------------------------------------
1.0303073128547828 ROGER VARGAS
--------------------------------------------------------------
Thanks for your attention
|
Checked. That was resulted by using the column precision information. Fixed. Please download the latest package. Thanks.
|
Just tried the new version, and now its work right.
Thanks for your quick help.
|