Strange Results When Writing To SQL Database

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
warrenk
Posts: 110
Joined: Sun Sep 21, 2008 5:39 am

Strange Results When Writing To SQL Database

Post by warrenk » Wed Jan 07, 2009 3:04 am

I am writing line item detail to a SQL database. The problem is the value written to PODLineNumber is always 6. This is strange as I have a total of 3 line items. When I run the code below, I am getting the following values:

gTotalLines = 3
tPOLine = 1,2,3

When I check the database, PODLineNumber is always 6. It doesn't matter how many line items I have, the PODLineNumber is always 6. PODLineNumber is setup as a integer. Any ideas? I am banging my head against the wall staring at this one!

answer gTotalLines
repeat with x = 1 to gTotalLines
put aItem[x] into tItem
put aDescription[x] into tDescription
put aCost[x] into tCost
put aLine[x] into tPOLine
answer tPOLine
revexecutesql gConID, "INSERT INTO podetail (PoDNumber, PODLineNumber, PoDItemNumber, PoDItemDesc, PoDUnitCost) values(:1,:2,:3,:4,:5)", "tPONumber","tPOLine", "tItem", "tDescription" , "tCost"
end repeat

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Wed Jan 07, 2009 7:19 am

I would think it's rather unhappy about the fact that you're trying to stuff a string "1,2,3" into an integer column. Why not just

Code: Select all

put x into tPOLine
inside the repeat loop?

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

warrenk
Posts: 110
Joined: Sun Sep 21, 2008 5:39 am

Post by warrenk » Wed Jan 07, 2009 8:21 pm

Jan,

I wasn't to clear when I mentioned the values of tPOLine = 1,2,3. I meant to say the values are:

1
2
3

...I put the commas in to separate them for the example but I am indeed using numerics.

I did find where the 6 was coming from for the PODLineNumber. It is putting the first digit from the PoDUnitCost into the PodLineNumber. Now the question is...why is this happening?

repeat with x = 1 to gTotalLines
put aItem[x] into tItem
put aDescription[x] into tDescription
put aCost[x] into tCost
put aLine[x] into tPOLine

answer tCost & "*" & tPONumber & "*" & tPOLine & "*" & tItem & "*" & tDescription

revexecutesql gConID, "INSERT INTO podetail (PoDNumber, PODLineNumber, PoDItemNumber, PoDItemDesc, PoDUnitCost) values(:1,:2,:3,:4,:5)", "tPONumber","tPOLine", "tItem", "tDescription" , "tCost"
end repeat

For the above code, I am getting the following on the dialog:

tPONumber = 4638
tPOLine = 1
tItem = Test Item 1
tDescription = Test Description 1
tCost = 12.12

tPONumber = 4638
tPOLine = 2
tItem = Test Item 2
tDescription = Test Description 2
tCost = 67.56

When I check my SQL database, the values are:

PODNumber = 4638
PODLineNumber = 1 (first digit from PodUnitCost)
PODItemNumber = Test Item 1
PodDescription = Test Description 1
PodUnitCost = 12.12

PODNumber = 4638
PODLineNumber = 6 (first digit from PodUnitCost)
PODItemNumber = Test Item 2
PodDescription = Test Description 2
PodUnitCost = 67.56

Any clue as to why my PodUnitCost is flowing into the PodLineNumber?

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Wed Jan 07, 2009 11:17 pm

Perhaps your SQL database has a log that can show the full INSERT statement after the variables are merged into it?

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Post Reply