Hallo,
I tested the same scenario with jdbc with the same result:
I can't set the cursor position to 0.
import java.sql.*;
public class CursorPosition2 {
static String server = "server";
static String db = "TST";
static String user = "DBA";
static String password = "DBA";
public static void main (String[] args){
String url = "jdbc:sapdb://" + server + "/"+ db;
//String url = "jdbc:adabasd://" + server + ":7200/"+ db;
try {
Class.forName("com.sap.dbtech.jdbc.DriverSapDB");
//Class.forName("de.sag.jdbc.adabasd.ADriver");
Connection connect = DriverManager.getConnection(url, user, password);
connect.setAutoCommit(true);
// Driver information
DatabaseMetaData meta = connect.getMetaData();
System.out.println("Driver version: " + meta.getDriverVersion());
// Creating table for test
System.out.println("Creating table 'CURSORPOSITION'");
connect.createStatement().executeUpdate(
"CREATE TABLE CURSORPOSITION(ID INTEGER NOT NULL)");
// Inserting data
System.out.println("Inserting data to table 'CURSORPOSITION' (10
rows)");
PreparedStatement pstmt = connect.prepareStatement(
"INSERT INTO CURSORPOSITION(ID) VALUES (?)");
for ( int i=1; i<=10; i++ ) {
pstmt.setInt(1, i);
pstmt.executeUpdate();
}
// Selecting data
System.out.println("Selection data from table 'CURSORPOSITION'");
Statement stmt = connect.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery(
"SELECT ID FROM CURSORPOSITION ORDER BY ID");
System.out.println("Stepping forward throw ResultSet");
while ( rs.relative(1) )
System.out.println("CURSOR POS: " + rs.getRow() +
", CONTENT: " + rs.getObject(1));
System.out.println("Setting cursor before first row");
// Doesn't work with SAP DB !!!
if ( rs.absolute(0) )
System.out.println("CURSOR POS: " + rs.getRow());
System.out.println("Stepping forward throw ResultSet");
while ( rs.relative(1) )
System.out.println("CURSOR POS: " + rs.getRow() +
", CONTENT: " + rs.getObject(1));
// Dropping table
System.out.println("Dropping table 'CURSORPOSITION'");
connect.createStatement().executeUpdate(
"DROP TABLE CURSORPOSITION");
} catch (Throwable t){
t.printStackTrace();
}
}
}
-----Urspr�ngliche Nachricht-----
Von: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]Im Auftrag von Kolja Kleist
Gesendet: Montag, 13. Mai 2002 17:28
An: [EMAIL PROTECTED]
Betreff: Problems setting cursor position to 0
Hallo,
I'm using SAP DB 7.3.0.21 with apache 1.3.23/php 4.1.2.
I compiled php with both variants, using a driver manager (iODBC) and
using --with-sapdb, but got the same behavior.
I'm trying to determine the size of a result (from a SELECT-Statement):
First i've got a strange effect with "order by" using the follwing code:
=====================================
function row_count($sth, $CurrentPos=0){
$count = 0;
odbc_fetch_row($sth, 0);
while (odbc_fetch_row($sth)) {
$count++;
}
//odbc_fetch_row($sth, $CurrentPos) // Second call to this function
always returns 0 while uncomment this line;
return $count;
}
$DSN = "myDB";
$user = "DBA";
$pass = "DBA";
$dbh = odbc_connect($DSN, $user, $pass);
$query = "select 'x' from dual";
echo "Executing: $query<br>";
$sth = odbc_exec($dbh, $query);
echo "First loop: " . row_count($sth) . "<br>";
echo "Second loop: " . row_count($sth) . "<br>";
$query = "select 'x' from dual order by 1";
echo "Executing: $query<br>";
$sth = odbc_exec($dbh, $query);
echo "First loop: " . row_count($sth) . "<br>";
echo "Second loop: " . row_count($sth) . "<br>";
odbc_close($dbh);
=====================================
OUTPUT:
Executing: select 'x' from dual
First loop: 1
Second loop: 1
Executing: select 'x' from dual order by 1
First loop: 1
Second loop: 0
=====================================
Second problem is, when I call odbc_fetch_row($sth, 0) and the cursor is on
position 0 the result will be lost!?
If I do something wrong or you have any comments,
please report them to me.
Regards,
Kolja
Mit besten Gruessen
Kolja Kleist (Senior Developer)
____________________________________
MediaTransfer AG
Netresearch & Consulting
Rothenbaumchaussee 38, 20148 Hamburg
Tel: (040) 669 625 16
Fax: (040) 669 625 29
URL: http://b2b.mediatransfer.de
____________________________________
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general