cancel
Showing results for 
Search instead for 
Did you mean: 

Possible issue in jconn3?! [Solved]

Former Member
8,629

Hello...

I have the code above:

create table t (id integer primary key, name varchar(40), dt timestamp);
insert into t values (1, 'test 1', now());
insert into t values (2, 'test 2', now());
insert into t values (3, 'test 3', now());
commit;
--wait some seconds
update t set name = 'New Name' where t.id = 1;
commit;
SELECT * FROM t;
--see the column dt


Forgiven... When i update any column, all timestamp columns also be updated, the new value is now()..

id name dt
1 New Name 2014-04-14 15:29:54.21
2 test 2 2014-04-14 15:28:42.56
3 test 3 2014-04-14 15:28:42.56

Solved: http://search.sybase.com/kbx/solvedcases?id_number=11433803

Accepted Solutions (1)

Accepted Solutions (1)

chris_keating
Product and Topic Expert
Product and Topic Expert

Apparently, it has been a very long time since we worked regularly with SQL Anywhere 9 and jConnect as it turns out that this is expected behaviour.

This behaviour is controlled by the automatic_timestamp option. When it is turned on, TIMESTAMP columns are provided a default value of TIMESTAMP. If the table has already been created via a TDS bases connection such as jConnect, you will need to change the column default from TIMESTAMP to another value ie., blank.

Answers (4)

Answers (4)

jack_schueler
Product and Topic Expert
Product and Topic Expert

As Chris Keating notes, much to our chagrin, this is expected behavior for ASA 9.0.2.

See: http://search.sybase.com/kbx/solvedcases?id_number=11433803

This has been an interesting investigation to say the least.

VolkerBarth
Contributor

Wow, the mystery of old options...

Just to add:

The mentioned T-SQL compatibility option "automatic_timestamp" has been discontinued in SA 11.0.0 - to cite:

automatic_timestamp New columns with the TIMESTAMP data type that do not have an explicit default value defined are never given a default value of the Transact-SQL timestamp.


So for v10 and below, I would think one could resolve the issue by either temporarily set that option to "off" or to use a login procedure that would do that automatically for TDS connections...

Former Member
VolkerBarth
Contributor
0 Kudos

FWIW, that's the naked CREATE TABLE statement from the RLL file (without a DEFAULT TIMESTAMP), so there is something strang going on:

I. 04/17 10:38:04. ** DONE    conn: 1     STMT_EXECUTE_ANY_IMM    
I. 04/17 10:38:45. ** REQUEST conn: 1     STMT_EXECUTE_ANY_IMM    "set rowcount @p0"
I. 04/17 10:38:45. ** DONE    conn: 1     STMT_EXECUTE_ANY_IMM    
I. 04/17 10:38:45. ** REQUEST conn: 1     STMT_EXECUTE_ANY_IMM    "create table t (id integer, name char(40), dt timestamp);
I. 04/17 10:38:45. insert into t values (1, 'AAA', now());"
I. 04/17 10:38:45. ** WARNING conn: 1     code: 105 "Procedure has completed"
I. 04/17 10:38:45. ** DONE    conn: 1     STMT_EXECUTE_ANY_IMM


And that's the UPDATE statement (without a value for the timestamp column):

I. 04/17 10:39:27. ** REQUEST conn: 1     STMT_EXECUTE_ANY_IMM    "set rowcount @p0"
I. 04/17 10:39:27. ** DONE    conn: 1     STMT_EXECUTE_ANY_IMM    
I. 04/17 10:39:27. ** REQUEST conn: 1     STMT_EXECUTE_ANY_IMM    "update t set name = 'New Name';"
I. 04/17 10:39:27. ** DONE    conn: 1     STMT_EXECUTE_ANY_IMM    
I. 04/17 10:39:34. ** REQUEST conn: 1     STMT_EXECUTE_ANY_IMM    "select * from t"
I. 04/17 10:39:34. ** WARNING conn: 1     code: 100 "Row not found"
I. 04/17 10:39:34. ** WARNING conn: 1     code: 105 "Procedure has completed"
I. 04/17 10:39:34. ** DONE    conn: 1     STMT_EXECUTE_ANY_IMM



Given Jack has already noticed the following (to quote from a comment from yesterday):

This has something to do with executing the following (under the hood by the JDBC driver)

set rowcount 100

these calls do appear here, too...

Former Member
0 Kudos

I don't understand!
I Follow exactly the instructions sent by Breck Carter to create the database..
I run create table and insert in my java program.
In the isql run select * from t
After, run update t set name='What a hell?'
In the isql i run select * from t and the column dt was updated!

😞

Former Member
0 Kudos

Anyone like to access my test PC for try?

VolkerBarth
Contributor
0 Kudos

I guess currently you have done all there is to do to show the problem, particularly when a true expert like Jack Schueler has committed to take the time to study that effect. - I would wait for his feedback...

VolkerBarth
Contributor
0 Kudos

That has been a fitting guess, apparently:)

jack_schueler
Product and Topic Expert
Product and Topic Expert

I think the problem is related to understanding that SQL Anywhere TIMESTAMP columns are quite different from ASE/SQL Server TIMESTAMP columns. ASE/SQL Server TIMESTAMP columns can be used for row versioning - they update automatically.

Not so with SQL Anywhere. Here TIMESTAMP is equivalent to the DATETIME data type. These columns do not update automatically.

Try this...

create table t (id integer primary key, name varchar(40), dt timestamp default timestamp );


Also see the documentation on DEFAULT TIMESTAMP and DEFAULT CURRENT TIMESTAMP.

Breck_Carter
Participant

The original question reported that a timestamp column without a default timestamp clause was being updated as if it did have a default timestamp clause... quite the opposite problem 🙂

jack_schueler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Then I'd like to see the JDBC connection string because I find it extremely hard to believe that this behavior occurs with a SQL Anywhere 9 database.

Former Member
0 Kudos

Really, using the datetime type, do the update correctly. But is there any property or way to do this using timestamp? I do not have autonomy over all tables, and several use timestamp .. Many thanks for the clarification!

Former Member
0 Kudos

Breck.. uses the clause "default timestamp" causes no difference in outcome

VolkerBarth
Contributor
0 Kudos

You surely do not use an user-defined datatype with a default that is automatically applied to the column?

Could you show us the actual table definition?

Breck_Carter
Participant
0 Kudos

> I find it extremely hard to believe

Indeed... if the engine was doing this, it would be one of the signs of the apocalypse 🙂

Breck_Carter
Participant
0 Kudos

We don't care about the other tables, we care about the CREATE TABLE you have shown us... is it, or is it not, the exact code that you have executed via SQuirreL?

Have you tried using jconn2.jar, or do you not read the responses?

Breck_Carter
Participant
0 Kudos

The actual table definition is in the question.

jack_schueler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Everything that I read indicates that DRauber is attempting to move ASA 9.0 schema to an ASE database and discovering that some things like TIMESTAMP columns don't work the same. DATETIME solves the problem. Why? Because DATETIME on ASE isn't TIMESTAMP.

chris_keating
Product and Topic Expert
Product and Topic Expert
0 Kudos

The behaviour that you are describing is 100% the behaviour of timestamp in an Adaptive Server ENTERPRISE database server. SQL Anywhere timestamp columns do not change value as a result of an update unless the schema includes a mechanism to cause the value to change such as a trigger or a column default value of timestamp i.e., dt timestamp default timestamp.

Can you post the output of the query

SELECT @@version

from whatever software (Squirel SQL?) that you are running that is showing the DT column being updated?

Former Member
0 Kudos

Yes, I tried with jconn2 and jconn3, btw, the result is the same!

Former Member
0 Kudos

I found the "problem":
Using Squirrel SQL, jconn2.jar, Sybase Sql ANYWHERE 9.0.2.3951
i perform this:

--drop table t; create table t (id integer, name char(40), dt timestamp default null);
insert into t values (1, 'A', now());
SELECT * FROM t;
--wait some seconds
UPDATE t set name = 'B';
SELECT * FROM t;
--the column dt is not updated (correct!!)

perform this:
--drop table t; create table t (id integer, name char(40), dt timestamp);
insert into t values (1, 'A', now());
SELECT * FROM t;
--wait some seconds
UPDATE t set name = 'B';
SELECT * FROM t;
--the column dt is updated (error!!)

If the default value is not set, causes the problem!

Thanks!

Former Member
0 Kudos

Certainly not the engine! Because through isql the result is correct! The hypothesis is JConnector.

jack_schueler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Not possible. Why do you show us the "drop table" line preceded by --? I think you are repeating the "insert into t" followed by the UPDATE. Shut down the server and restart it with these options ...

dbeng9 -zr sql -o test9.txt your-database.db

Then rerun your test, edit test9.txt, and copy/paste the results here on the forum. Then you might have a believer!

Former Member
0 Kudos

I do better.. If you can, access the pc by teamviewer
ID - 237 056 878
PWD - 5910
And see with your eyes 😄

thanks a lot!!

jack_schueler
Product and Topic Expert
Product and Topic Expert
0 Kudos

OK, I downloaded Squirrel, connected with jconn2, and I am now a believer. I will investigate this more tomorrow to figure out what is going on. Is there an ASE compatibility option for TIMESTAMP column behavior?

This has something to do with executing the following (under the hood by the JDBC driver)

set rowcount 100

Breck_Carter
Participant

Betcha it's something SQuirreL is doing all by itself... keep us posted!

VolkerBarth
Contributor
0 Kudos

Feel free to drop/modify these TeamViewer access, if not already done...

Former Member
0 Kudos

Good morning friends! Many thanks for your attention so far. I wrote a small application in java using the Jconn2 to confirm whether the squirrel is the culprit or not. I came to a conclusion, it is not! When the table is created using the Jconn2, the column value by default is as timestamp. When the table is created by isql, the column value by default is blank. java program: http://ubuntuone.com/3rKVK1uK4W3wN3pUJcwumT

Thank you very much.

VolkerBarth
Contributor
0 Kudos

So the actual table definition does differ w.r.t. column defaults, i.e. when you enter

 create table t (id integer, name char(40), dt timestamp);


the table is created as

 create table t (id integer, name char(40), dt timestamp default null);


? Are there further differences, say with respect to NULL/NOT NULL - where ASE and SA have different defaults, as well? Confine this doc page from SA 12.0.1.

(I'm asking as not everyone interested in this FAQ may be ready to download further contents from other sites and try to re-do your own tests...)

Former Member
0 Kudos

I understand..
let me say that the conclusion arrived, using jconn2 or jconn3:

create table t (id integer, name char(40), dt timestamp);


JConnector add the option "default timestamp" in dt column.

create table t (id integer, name char(40), dt timestamp default null);


JConnector create the table with default null.

ie the default JConnector arrow as default timestamp for timestamp columns.

Thanks..

Breck_Carter
Participant
0 Kudos

Please run your SQuirreL test against an empty SQL Anywhere 9 database with "request level logging" turned on.

Here's how to create and start that database:

"%ASANY9%\\win32\\dbinit.exe" ddd9.db
"%ASANY9%\\win32\\dbeng9.exe" -o "c:\\temp\\ddd9log.txt" -zr sql ddd9.db 

Here's how to connect:

ENG=ddd9;DBN=ddd9;UID=dba;PWD=sql;

Please post the entire "c:\\temp\\ddd9log.txt" log file so we can see what the server is seeing.

It will contain all the SQL coming from the client side; for example:

I. 04/17 09:15:58. ** REQUEST conn: 1     STMT_PREPARE            "select * from dummy"