Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WEIRD!!! Problems when inserting and updating

Posted on 1998-12-09
9
Medium Priority
?
197 Views
Last Modified: 2011-09-20
This is causing me an awful amount of hastle!!!! I have a delphi program which talks to a SQL SERVER database over an ODBC link.... so far so good! ...... The program interacts with the user and, depending on changes made, creates a few SQL statements which run as one transaction.

It gets a bit tricky here but, what follows are the statements I'm trying to run as ONE transaction.

DELETE FROM COLLECTIONS WHERE ID = 24
DELETE FROM DELIVERY WHERE ID = 24
DELETE FROM LOADS WHERE LOAD_NUMBER = '4'

UPDATE dbo.DIARY SET LORRY_ID = 1, DRIVER_ID = 0, TEXT = 'Hello World', DATE = '12/08/98' WHERE ID = 3

DECLARE @@MYLOADID INTEGER

INSERT INTO LOADS (LOAD_NUMBER, TRAILER_ID, TYPE_OF_GOODS, COMPLETED, CUSTOMER_ID, DIARY_ID) VALUES ('4', 0, 'COMPUTERS', 'N', 2, 3)

SELECT @@MYLOADID = @@IDENTITY

INSERT INTO DELIVERY (LOAD_ID, ADDRESS_ID, DATE, DELIVERED, DIARY_ID) VALUES (@@MYLOADID, 1, '12/08/98', 'N',3)

INSERT INTO COLLECTIONS (LOAD_ID, ADDRESS_ID, DATE) VALUES (@@MYLOADID, 3, '12/08/98')

UPDATE DELIVERY SET DELIVERED = 'Y' WHERE (LOAD_ID = (SELECT ID FROM LOADS WHERE LOAD_NUMBER = '4')) AND (ADDRESS_ID = 1)

Now, just so you know there is a certain amount of referential integrity in the database BUT nothing which should cause the problem I'm having.

At the time these statements are run the relevant records are available in the database for deletion, update, etc.

The PROBLEM (now we get to it) is this.  Before I run these statements there IS some text in the 'TEXT' column in the DIARY table (Let's say "HERE IS THE TEXT") but when I run the above statements in this order the text gets deleted instead of UPDATED to "Hello World".

If I run the Update statement on its own it works BUT when I run the statements in the above order it dosen't.  I DON'T get any error message..

Can some genius help????  PLEASE! before I go round the twist..

Thanks
Nigel.
0
Comment
Question by:nigelbogle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 3

Expert Comment

by:cognition
ID: 1092168
You will need to use READTEXT, WRITETEXT, and UPDATETEXT, rather than normal string manipulation when using stored procedures.
Have a look in books online.

In VB there are methods such as getchunk, and appendchunk for dealing with Text and Image data. There are probably equivalents in Delphi.
0
 

Author Comment

by:nigelbogle
ID: 1092169
Thanks cognition for the answer I appreciate your swift response but the statements are the problem not the method of getting the text in and out.

The SQL statements are run using a TQuery under transaction control.  All the statements should execute or there will be a rollback.  The statements seem to execute OKAY due to the fact that the correct data is in the tables to allow them to do so but when I look in the TEXT COLUMN of the DIARY TABLE, the COLUMN has been cleared completely when it should show the text "Hello World"

Thanks anyway.

Nigel.
0
 
LVL 3

Expert Comment

by:jjbyers
ID: 1092170
Have you tried breaking the Delete statements out to their own transaction?

The problem may be in the transaction caching.

Hope this helps.

Thanks
Jeff
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:nigelbogle
ID: 1092171
Jeff,

I tried separating the delete part into its own section but still NO joy!!!  The Text column is still blank?????

Thanks all the same. I'm grateful for the effort.
Nigel
0
 

Expert Comment

by:mhamra
ID: 1092172
try to change the update of diary table with this statements:

DECLARE @@ptrval varbinary(16)
SELECT @@ptrval = TEXTPTR(text)
      FROM diary
      WHERE ID = 3

WRITETEXT diary.text @@ptrval 'hello world'

I hope will solve your problem
0
 

Author Comment

by:nigelbogle
ID: 1092173
mhamra,

Thank-you for your answer..... This problem is proving difficult I think even for those with some know-how.... I tried what you suggested but it didn't work the column is still blank...

I get the feeling that the effect is to do with the other statements surrounding the set of statements....

But that's only a guess...

Thanks anyway mhamra!  Keep trying everyone.
0
 
LVL 2

Expert Comment

by:martyn_bannister
ID: 1092174
Don't suppose there are any triggers on LOADS, DELIVERY or COLLECTIONS?
0
 

Author Comment

by:nigelbogle
ID: 1092175
No, Sorry.......  This one really is proving really difficult for everybody!!!

Thanks for the try...

Nigel.
0
 

Accepted Solution

by:
rounded225 earned 200 total points
ID: 1092176
Use SQL trace to make sure that the sql statement you intended to send was not translated into something completely different.

MS
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question