on 2014 Apr 14 3:20 PM
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
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
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!
😞
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...
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 🙂
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?
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!
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!
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
Betcha it's something SQuirreL is doing all by itself... keep us posted!
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.
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...)
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..
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
53 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.