Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v5.2
  HXTT Cobol v2.1
  HXTT DBF v5.2
 
  Buy Now
  Support
  Download
  Document
  FAQ
  HXTT Excel v4.2
  HXTT Paradox v5.2
  HXTT Text(CSV) v5.2
  HXTT XML v1.2
Offshore Outsourcing
Oracle Data Import/Export
DB2 Data Import/Export
Sybase Data Import/Export
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
   
   
   
Hongxin Technology & Trade Ltd. of Xiangtan City (abbr, HXTT)

HXTT DBF
Problems with DISTINCT, if one row is marked as deleted
Tobi
2009-01-12 00:48:10.0
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.0
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.0
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.0
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.0
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.0
Thanks, too. I'll try the next version.

Search Key   Search by Last 50 Questions




Google
 

Address: 9 Station Rd., Xiangtan City, Hunan Province, P.R. China
Postcode: 411100
Phone: (86)731-58225727
Fax: (86)731-58225727
Email: webmaster@hxtt.com
Copyright © 1999-2011 Hongxin Technology & Trade Ltd. | All Rights Reserved. | Privacy | Legal | Sitemap