473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

insert (now(),now(),....)

I've a query with insert records in a table.

I've 2 fields: DateTimeInsertion and DateTimeLastModification.

When I create the record, I must have those 2 fields set the same value.

Now I've this

Insert into article values(now(), now(),....)

but what appens if the time changes between the 2 now calls ?

It's there any way to be sure to set the same value ?

Thanks

Bob

PS: I've no access to MySQL NG.

Jul 17 '05 #1
2 2403
Bob Bedford wrote:
Insert into article values(now(), now(),....)
but what appens if the time changes between the 2 now calls ?


In MySQL, it shouldn't, because MySQL guarantees a single statement to be
atomic, even if no other transactional mechanism is being used.

If you decide to use user variables, you'd be on the safe side, anyway.

http://dev.mysql.com/doc/mysql/en/ex...variables.html,
http://dev.mysql.com/doc/mysql/en/variables.html
"MySQL supports user variables as of version 3.23.6. You can store a value
in a user variable and refer to it later, which allows you to pass values
from one statement to another. User variables are connection-specific. That
is, a variable defined by one client cannot be seen or used by other
clients. All variables for a client connection are automatically freed when
the client exits."

mysql> select version();
+------------+
| version() |
+------------+
| 4.0.18-Max |
+------------+
1 row in set (0.00 sec)
mysql> select @t := now();
+---------------------+
| @t := now() |
+---------------------+
| 2005-03-21 11:10:17 |
+---------------------+
1 row in set (0.00 sec)
mysql> select @t;
+---------------------+
| @t |
+---------------------+
| 2005-03-21 11:10:17 |
+---------------------+
1 row in set (0.00 sec)
mysql> create table tab ( time_a datetime, time_b datetime);
Query OK, 0 rows affected (0.24 sec)

mysql> insert into tab (time_a, time_b ) values ( @t, @t);
Query OK, 1 row affected (0.00 sec)

Kristian

Jul 17 '05 #2
Bob Bedford wrote:
I've a query with insert records in a table.

I've 2 fields: DateTimeInsertion and DateTimeLastModification.

When I create the record, I must have those 2 fields set the same value.

Now I've this
Insert into article values(now(), now(),....)

but what appens if the time changes between the 2 now calls ?

It's there any way to be sure to set the same value ?


Try setting one date variable and inserting it into all date fields you
want to update with now();

$time_now = date("Y-m-d H:i:s"); // the current date/time
$query = "insert into test.test
values(\"{$time_now}\",\"{$time_now}\",\"{$time_no w}\")";

mysql_query($query) or die('Query error: ' . mysql_error());

$query = "select * from test.test";
$res = mysql_query($query);

while(($row = mysql_fetch_assoc($res)) != null){
echo " datetime1 = ".$row["date1"];
echo " datetime2 = ".$row["date2"];
echo " datetime3 = ".$row["date3"];
echo "\n";
}
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Micke | last post by:
I have a problem with string insert that I hope someone can help me with. I'm doint a one-line insert into my database from an other program and it works perfect (thanks to Bill Karwin): ...
2
by: sm | last post by:
How to "Insert" (not append) new text segment to an existing text file? Assume that we have text file as shown below; Elvis Sofia Kylix BCB--> How to insert here? Atten BuilderX Roma
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
4
by: JMCN | last post by:
i received a runtime error message 3346 when i ran the insert into select code. i have check to see if the query values and destination fields are the same and it appears so. atlas, i have no idea...
5
by: Annie | last post by:
hello guys, I have little experience working with C# and MS Access ... I am having an insert query with one datetime field and a boolean and couple of text and number fields as below: ...
21
by: lesperancer | last post by:
I've got an access97 reporting mdb that pulls data (77,000 rows) from a sql server table into a local table to run reports if the local table is part of the reporting MDB, the insert statement...
1
by: shallowpool | last post by:
Can someone provide me the simple syntax necessary to insert or update to a row containing a single BLOB column, where the BLOB data will be obtained from a file? This is on a linux installation. ...
3
by: pavanponnapalli | last post by:
hi, I have designed a module, which contains a template for insert command. The code is as under: my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = ...
0
by: Donna Long | last post by:
Got new Windows 7 and now am unable to insert photos on our site in Front Page. I can change text but no photos. "Insert">"Picture"> from "File". Window starts to open then snaps closed immediately.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.