|
The float built-in only takes a single parameter, you are passing two, so that code will fail. Also you have specified two values in your insert statement but you are trying to pass only one.Victor pointed out my mistake.
[edit]
Having looked at the documentation, I guess that the extra parentheses round your values may be the problem. The example is:
cursor.execute("insert into products(id, name) values (?, ?)", 'pyodbc', 'awesome library')
So perhaps your code should be:
cur2.execute('INSERT INTO RawValues (Millitime, PowerCost) VALUES (?,?)', float(row[0]), row[1])
[/edit]
modified 6-Dec-18 7:54am.
|
|
|
|
|
Richard MacCutchan wrote: The float built-in only takes a single parameter, you are passing two, so that code will fail. Also you have specified two values in your insert statement but you are trying to pass only one.
Hmmm...
It seems to me there are two values here:
Quote:
cur2.execute('INSERT INTO RawValues (Millitime, PowerCost) VALUES (?,?)',(float(row[0]),row[1]))
The first is Quote: float(row[0]) , the second - Quote: row[1]
|
|
|
|
|
Thanks, my eyesight missed that.
|
|
|
|
|
Richard MacCutchan wrote: Having looked at the documentation, I guess that the extra parentheses round your values may be the problem. The example is:
cursor.execute("insert into products(id, name) values (?, ?)", 'pyodbc', 'awesome library')
So perhaps your code should be:
cur2.execute('INSERT INTO RawValues (Millitime, PowerCost) VALUES (?,?)', float(row[0]), row[1])
No, the 'extra' parentheses turn the two values to be passed into a single (2-element) Python Tuple, which is what the call wants passed. If this were the problem, Python should be throwing an error. I have written a fair bit of other code, adding data to SQLite tables, which is exactly parallel and works as it should.
|
|
|
|
|
You will have to do some debugging as it is impossible to guess what is happening on your system. Does the execute command return a value, such as the number of rows inserted?
|
|
|
|
|
It returns a cursor. Fetching the contents of that gets the following:
pyodbc.ProgrammingError: No results. Previous SQL was not a query. That does make a certain amount of sense, given that nothing is happening , but doesn't really help, particularly since the syntax I am using appears valid and works with Sqlite. I was hoping that someone else had run into and solved this specific problem, since I am out of ideas.
[EDIT] Further research suggests that this 'error' is even less helpful, and may well be the normal result when executing something that is not a SELECT query. [/EDIT]
modified 6-Dec-18 11:41am.
|
|
|
|
|
Sorry, I am out of ideas, and the documentation is not a lot of help. Although a number of similar questions suggest that it should return a row count.
|
|
|
|
|
I have been playing with pyodbc and have successfully added records to my pre-built access database. Unfortunately that does not give any clues as to why your code fails.
[edit]
Created a RawValues table and successfully added a record with 2 values.
[/edit]
modified 8-Dec-18 11:41am.
|
|
|
|
|
Can you post your working Python code, and what version/'bitness' of Access are you running?
|
|
|
|
|
No need, I just discovered I am blind (and maybe you are). The following calls are missing the parentheses that make them into function calls:
conn2.commit
conn2.close
conn1.close
conn2.commit()
conn2.close()
conn1.close()
|
|
|
|
|
|
I see it happens to the best of us.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
It happens to me embarrassingly too often. 
|
|
|
|
|
|
That is a SELECT statement. What are we supposed to do with it?
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Member 2458467 wrote: what is the error We don't know; the programmer choose to not display the exception he caught, but the command he issued.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
The software runs fine in winXP but not good in win7, as I think it's good connection in win7 but lost some permissions so can not read
|
|
|
|
|
It is better to catch the exception and CHECK what is the matter, as opposed to guessing.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
This is an old application with no code
|
|
|
|
|
Without knowing the exception, you're basically guessing what the problem might be. Guessing is not my department.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Tell us exactly what the error says
|
|
|
|
|
Hi,
I am getting the following error when I am trying to run a SQL Query with larger Data, any help how can I run the select statement.
SELECT
CASE WHEN PTT.POSTransactionTypeCode = 'A' THEN 'A'
WHEN PTT.POSTransactionTypeCode = 'C' THEN 'C'
WHEN PTT.POSTransactionTypeCode = 'R' THEN 'R'
WHEN PTT.POSTransactionTypeCode = 'I' THEN 'C'
END AS TransactionType,
CASE WHEN PTT.POSTransactionTypeCode = 'A' THEN 'A'
WHEN PTT.POSTransactionTypeCode = 'C' THEN 'A'
WHEN PTT.POSTransactionTypeCode = 'R' THEN 'A'
WHEN PTT.POSTransactionTypeCode = 'I' THEN 'I'
END AS ProviderStatus,
-- right format. uncomment when the PIN numbers are fixed.
'00000' + C.ProviderNbr + SPACE(1) AS ContractNbr,
-- right format. uncomment when sending the provider numbers that were added wrongly.
--'000000' + C.ContractNbr AS ContractNbr,
'01' AS Other,
'000000' AS PIN,
UPPER(LEFT(C.ProviderName, 28)) AS ContractName,
'PROGRAM DIRECTOR' + SPACE(8) AS ContractAddressAttention,
UPPER(LEFT(A.StreetAddress1, 24)) AS Address1,
UPPER(LEFT(A.StreetAddress2, 24)) AS Address2,
UPPER(LEFT(A.City, 17)) AS City,
UPPER(S.PK_Geographic_Location_Code) AS State,
LEFT(A.Zip1, 9) AS ZipCd,
SPACE(12) AS ErrorCode2,
SPACE(8) AS Filler
FROM
POSPINTransaction AS E INNER JOIN
Provider AS C ON E.FKProviderId = C.PKProviderId INNER JOIN
ProviderDate AS PD ON dbo.Udf_GetPKProviderDate(C.PKProviderId) = PD.PKContractDate INNER JOIN
ProviderAddress AS PA ON PA.FKProviderId=C.PKProviderId INNER JOIN
[Address] AS A ON A.PKAddressId = PA.FKAddressId INNER JOIN
--ParentTypeLKP AS PT ON A.FKParentType = PT.PKParentType AND PT.ParentTypeCd = 'usrContract' INNER JOIN
[State] AS S ON A.FK_State = S.PKStateId INNER JOIN
POSTransactionTypeLKP PTT ON E.FKPOSTransactionTypeId=PTT.PKPOSTransactionTypeId
WHERE
(PA.IsCurrentAddress = 1) AND (E.TransactionSentDate IS NULL) AND (E.TransactionReceivedDate IS NULL) AND (E.FKPOSTransactionTypeId IN (SELECT PKPOSTransactionTypeId FROM POSTransactionTypeLKP WHERE POSTransactionTypeCode IN ('A', 'C', 'R'))) OR
(PA.IsCurrentAddress = 1) AND (E.TransactionSentDate IS NULL) AND (E.TransactionReceivedDate IS NULL) AND (E.FKPOSTransactionTypeId = (SELECT Top 1 PKPOSTransactionTypeId FROM POSTransactionTypeLKP WHERE POSTransactionTypeCode = 'I')) AND (PD.EffectiveDateTo IS NULL) OR
(PA.IsCurrentAddress = 1) AND (E.TransactionSentDate IS NULL) AND (E.TransactionReceivedDate IS NULL) AND (PD.EffectiveDateTo <= GETDATE())
UNION
SELECT
CASE WHEN PTT.POSTransactionTypeCode = 'A' THEN 'A'
WHEN PTT.POSTransactionTypeCode = 'C' THEN 'C'
WHEN PTT.POSTransactionTypeCode = 'R' THEN 'R'
WHEN PTT.POSTransactionTypeCode= 'I' THEN 'C'
END AS TransactionType,
CASE WHEN PTT.POSTransactionTypeCode = 'A' THEN 'A'
WHEN PTT.POSTransactionTypeCode = 'C' THEN 'A'
WHEN PTT.POSTransactionTypeCode = 'R' THEN 'A'
WHEN PTT.POSTransactionTypeCode = 'I' THEN 'I'
END AS ProviderStatus, SP.NPINumber AS ContractNbr,
'01' AS Other,
'000000' AS PIN,
UPPER(LEFT(SP.FirstName, 28)) AS ContractName,
'PROGRAM DIRECTOR' + SPACE(8) AS ContractAddressAttention,
UPPER(LEFT(ADDR.StreetAddress1, 24)) AS Address1,
UPPER(LEFT(ADDR.StreetAddress2, 24)) AS Address2,
UPPER(LEFT(ADDR.City, 17)) AS City,
UPPER(ST.PK_Geographic_Location_Code) AS State,
LEFT(ADDR.Zip1, 9) AS ZipCd,
SPACE(12) AS ErrorCode2,
SPACE(8) AS Filler
FROM
POSPINTransaction AS EDS INNER JOIN
NPIAssociation NA ON NA.FKParentId=EDS.FKProviderId AND NA.FKParentTypeLKPId = (SELECT Min(PKParentTypeLKPId) FROM ParentTypeLKP WHERE ParentCode='PRV') INNER JOIN
NPI AS SP ON SP.PKNPIId = NA.FKNPIId LEFT OUTER JOIN
POSTransactionError AS EDSERR ON EDSERR.FKPOSPINTransactionId = EDS.PKPOSPINTransactionId LEFT OUTER JOIN
POSTransactionErrorLKP AS EDSERRCD ON EDSERRCD.PKPOSTransactionErrorLKPId = EDSERR.FKPOSTransactionErrorLKPId LEFT OUTER JOIN
NPIAddress AS NPIADDR ON NPIADDR.FKNPIId = SP.PKNPIId AND NPIADDR.IsCurrentAddress = 1 INNER JOIN
[Address] AS ADDR ON ADDR.PKAddressId=NPIADDR.FKAddressId INNER JOIN
[State] AS ST ON ADDR.FK_State = ST.PKStateId INNER JOIN
County AS CO ON CO.PKCountyId = ADDR.FK_County INNER JOIN
POSTransactionTypeLKP PTT ON EDS.FKPOSTransactionTypeId=PTT.PKPOSTransactionTypeId
WHERE
(EDS.TransactionSentDate IS NULL) AND (EDS.TransactionReceivedDate IS NULL) AND
(EDS.FKPOSTransactionTypeId IN (SELECT PKPOSTransactionTypeId FROM POSTransactionTypeLKP WHERE POSTransactionTypeCode IN ('A', 'C', 'R'))
OR EDS.FKPOSTransactionTypeId = (SELECT Top 1 PKPOSTransactionTypeId FROM POSTransactionTypeLKP WHERE POSTransactionTypeCode = 'I'))
Let me know if I can refine the script or any other advice is also welcome please thanks in advance friends.
|
|
|
|
|
System.OutOfMemoryException just means that the code is using too much space. The only way to fix it is to reduce the amount of data that you are trying to process in one go.
|
|
|
|
|
You need to cut back how many records and or fields you are returning.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Hi,
I have couple of larger tables in my Database, but when I am trying to generate script for data of those tables using SSMS Wizard, I getting red sign and its failing, any help how can I generate data for the larger tables using Generate Script or some other option? thanks in advance my friends.
|
|
|
|
|