Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v7.1
  HXTT Cobol v5.0
  HXTT DBF v7.1
 
  Buy Now
  Support
  Download
  Document
  FAQ
  HXTT Excel v6.1
  HXTT Json v1.0
  HXTT Paradox v7.1
  HXTT PDF v2.0
  HXTT Text(CSV) v7.1
  HXTT Word v1.1
  HXTT XML v4.0
Offshore Outsourcing
Free Resources
  Firewall Tunneling
  Search Indexing Robot
  Conditional Compilation
  Password Recovery for MS Access
  Password Recovery for Corel Paradox
  Checksum Tool for MD5
  Character Set Converter
  Pyramid - Poker of ZYH
   
   
   
Heng Xing Tian Tai Lab of Xi'an City (abbr, HXTT)

HXTT DBF
Problems with DISTINCT, if one row is marked as deleted
Tobi
2009-01-12 00:48:10
Hi everybody,

I have a problem with the function DISTINCT. If a row is marked as deleted, in a special case the ResultSet is wrong.

Here is an example. First of all I create a new table. If it already exists, I delete the old one. Then I fill it with values. After that, I delete one entry.
Have a look at the comment after the DELETE-Statement (line 38/39)

---------------------------------------------------
import java.io.File;
import java.sql.*;

public class MinimalClass {
public static void main(String[] args) {
String pathToDBF = "c:/dbf";
String connectionUrl;
Connection con;
Statement stmt;
String sSQL;

connectionUrl = "jdbc:dbf:/" + pathToDBF;

try {
// Delete the dbf-File if necessary
File file = new File(pathToDBF + "/t1.dbf");
if (file.exists()) {
file.delete();
}

Class.forName("com.hxtt.sql.dbf.DBFDriver");
con = DriverManager.getConnection(connectionUrl);
stmt = con.createStatement();

// create a Table
sSQL = "CREATE TABLE IF NOT EXISTS t1 (key INT, val INT)";
stmt.executeUpdate(sSQL);

// fill with values
sSQL = "INSERT INTO t1 (key, val) VALUES (1,1)";
stmt.executeUpdate(sSQL);
sSQL = "INSERT INTO t1 (key, val) VALUES (2,2)";
stmt.executeUpdate(sSQL);
sSQL = "INSERT INTO t1 (key, val) VALUES (3,2)";
stmt.executeUpdate(sSQL);

// delete one value
sSQL = "DELETE FROM t1 WHERE key=3";
// change key=3 to key=2 in the line above and compare the result
stmt.executeUpdate(sSQL);

// Output
sSQL = "SELECT DISTINCT(val) AS myRow FROM t1";
ResultSet rs = stmt.executeQuery(sSQL);
while (rs.next()) {
System.out.println(rs.getInt("myRow"));
}
rs.close();

stmt.close();

} catch (Exception e) {
e.printStackTrace();
}
}
}
---------------------------------------------------

I know, that I can use "GROUP BY" instead of DISTINCT, but in other cases this might not work.
Re:Problems with DISTINCT, if one row is marked as deleted
Tobi
2009-01-12 00:51:32
Sorry for the unformated java-Code. I hope you can read it anyway :-) Is there a possibility to edit my posting?
Re:Re:Problems with DISTINCT, if one row is marked as deleted
HXTT Support
2009-01-12 19:39:12
Checked. It output:
1
2

It's normal. What's your wrong?
Re:Re:Re:Problems with DISTINCT, if one row is marked as deleted
Tobi
2009-01-12 23:52:09
If I use

DELETE FROM t1 WHERE key=2

I get the ResultSet
1
Re:Re:Re:Re:Problems with DISTINCT, if one row is marked as deleted
HXTT Support
2009-01-13 03:59:16
Thanks. v4.2.031 fixed a bug for DISTINCT operation, which missed the possible data row when there's deleted row with the same value.

BTW, there's no distinct function, so that your sql is
SELECT DISTINCT val AS myRow FROM t1 ;
in fact.
You can use DISTINCT flag on aggregatetion function, or SELECT DISTINCT on (val) val as myrow from t1;... and so on.
Re:Re:Re:Re:Re:Problems with DISTINCT, if one row is marked as deleted
Tobi
2009-01-13 04:01:16
Thanks, too. I'll try the next version.

Search Key   Search by Last 50 Questions




Google
 

Email: webmaster@hxtt.com
Copyright © 2003-2019 Heng Xing Tian Tai Lab of Xi'an City. | All Rights Reserved. | Privacy | Legal | Refund | Sitemap