I am sorting out an error for my database so I have tried to isolate the problem. This function is the problem but more specifically the c.execute("INSERT INTO details VALUES(?, ?)",(e ,cp ,)).
This causes this error:
c.execute("INSERT INTO details VALUES(?, ?)",(e ,cp ,))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
I'll put the rest of the function underneath:
import sqlite3
def echecker():
email = False
password = False
right = 0
e = "the#test.com"
p = "test"
cp = "test"
space = 0
conn = sqlite3.connect("U+P.db")
c = conn.cursor()
c.execute("""SELECT email FROM details""")
data = c.fetchall()
conn.commit()
index = 0
for row in data:
if row[index] == e:
right = right + 1
else:
print("right")
print()
e = list(e)
print(e)
while space < len(e) and right == 0 and email == False:
if e[0] == "#" and e[space] == "#":
space = space + 1
print("wrong")
elif e[space] == "#":
email = True
print("right")
else:
space = space + 1
print("wrong")
print()
if p == cp:
password = True
print("right")
print()
if password == True and email == True and right == 0:
conn = sqlite3.connect("U+P.db")
print("a")
c = conn.cursor()
print("a")
c.execute("INSERT INTO details VALUES(?, ?)",(e ,cp ,))
print("a")
conn.commit()
print("siuu")
echecker()
Well, you reassign e to a list e = list(e). Of course the subsequent attempt to supply e as a query parameter will fail.
Related
I've created my SQLITE3 database using a tutorial online where the records where loaded in tkinter entries and then saved from there. In the tutorial there was a id_entry that was used for the remove_one, remove_many, remove_all and the update_record function. I've removed that entry and I'm trying to use "rowid" instead, but unfortunly my code is not working:
When using remove_one it is deleted only one record, but when I close my app and restart every record is missing.
remove_many and update_record actually works, but when I close and I open again the app the changes are not saved.
I'd like to understand what I'm doing wrong. Thank you for your help!
P.S.(I've made some change to the code to make it shorter and more understandable, if there is some inconsistency it could be the reason. The code right now does not give me back any kind of error at all)
Create database
conn = sqlite3.connect('records_list.db')
c = conn.cursor()
c.execute("""CREATE TABLE if not exists records (
author text,
year text,
title text,
page text,
""")
conn.commit()
conn.close()
Query database
def query_database():
global count
count = 0
for record in record_tree.get_children():
record_tree.delete(record)
conn = sqlite3.connect('records_list.db')
c = conn.cursor()
c.execute("SELECT rowid, * FROM records")
records = c.fetchall()
for record in records:
if count % 2 == 0:
record_tree.insert(parent='', index='end', iid=count, text='', values=(record[1], record[2], record[3], record[4], tags=('evenrow',))
else:
record_tree.insert(parent='', index='end', iid=count, text='', values=(record[1], record[2], record[3], record[4], tags=('oddrow',))
count += 1
conn.commit()
conn.close()
Remove many
def remove_many():
response = messagebox.askyesno("WOAH!!!!", "This Will Delete EVERYTHING SELECTED From The Table\nAre You Sure?!")
if response == 1:
x = record_tree.selection()
ids_to_delete = []
for record in x:
ids_to_delete.append(record_tree.item(record, 'values')[0])
for record in x:
record_tree.delete(record)
conn = sqlite3.connect('records_list.db')
c = conn.cursor()
c.executemany("DELETE FROM records WHERE rowid = ?", [(a,) for a in ids_to_delete])
ids_to_delete = []
conn.commit()
conn.close()
clear_entries()
Remove one
def remove_one():
x = record_tree.selection()[0]
record_tree.delete(x)
conn = sqlite3.connect('records_list.db')
c = conn.cursor()
c.execute("DELETE from records WHERE oid=" + 'rowid')
conn.commit()
conn.close()
clear_entries()
messagebox.showinfo("Deleted!", "Your record Has Been Deleted!")
update_record
def update_record():
selected = record_tree.focus()
record_tree.item(selected, text="", values=(author_entry.get(), year_entry.get(), title_entry.get(), journal_entry.get(), volume_entry.get(), number_entry.get(), page_entry.get(), doi_entry.get(),))
conn = sqlite3.connect('records_list.db')
c = conn.cursor()
c.execute("SELECT rowid, * FROM records")
records = c.fetchall()
c.execute("""UPDATE records SET
author = :author,
year = :year,
title = :title,
page = :page,
WHERE oid = :oid""",
{
'author': author_entry.get(),
'year': year_entry.get(),
'title': title_entry.get(),
'page': page_entry.get(),
'oid': "rowid",
})
conn.commit()
conn.close()
clear_entries()
The main issue is that the value of x (result of record_tree.selection()[0]) and selected (result of record_tree.focus()) are not the actual rowid in the database. You need to save the rowid to iid option when inserting the records into treeview:
c.execute("SELECT rowid, * FROM records")
records = c.fetchall()
count = 0
for record in records:
if count % 2 == 0:
# record[0] is the rowid
record_tree.insert(parent='', index='end', iid=record[0], values=(record[1], record[2], record[3], record[4]), tags=('evenrow',))
else:
record_tree.insert(parent='', index='end', iid=record[0], values=(record[1], record[2], record[3], record[4]), tags=('oddrow',))
count += 1
Then to delete the selected record in treeview:
...
selected = record_tree.selection()
if selected:
record_tree.delete(selected[0])
c.execute('DELETE FROM records WHERE rowid = ?', (selected[0],))
conn.commit()
...
Similar logic applies on updating record.
I want to get arguments from user and use them in function, but the types are different.
Note: a comment is there in bottom of code that is correctly work
but I want to get arguments directly
Thanks for your help
from string import ascii_letters
def encrypt(string , key):
alpha = ascii_letters
result = ''
for ch in string :
if ch not in alpha :
result += ch
else :
new_key = (alpha.index(ch) + key.str() ) % len(alpha)
result += alpha[new_key]
return result
def decrypt(string , key):
key *= -1
return encrypt(string , key)
state = ''
print("please enter 'e' to encrpyt & type 'd' to decrpyt :...")
state = input()
if state == 'e' :
print("please enter the str that you want to encrypt :... ")
c_str1 = input()
print("\nplease enter the key that shifts strings(e.x. 1 to 52):... ")
c_in1=input()
encrypt(c_str1, c_in1)
elif state == 'd':
print("please enter the str that you want to decrypt :... ")
c_str= input('')
print("\nplease enter the key (e.x. 1 to 52):... ")
c_in = input()
decrypt(c_str, c_in )
# print(decrypt('amir',4))
not sure what your question is , here my attempt at making your code run,
not sure runs as you expected:
from string import ascii_letters
def encrypt(string , key):
result = ''
alpha = ascii_letters
for ch in string :
if ch not in alpha :
result += ch
else :
new_key = (alpha.index(ch) + int(key)) % len(alpha)
result += alpha[new_key]
return result
def decrypt(string , key):
key *= -1
return encrypt(string , key)
state = ''
print("please enter 'e' to encrpyt & type 'd' to decrpyt :...")
state = input()
if state == 'e' :
print("please enter the str that you want to encrypt :... ")
c_str1 = input()
print("\nplease enter the key that shifts strings(e.x. 1 to 52):... ")
c_in1 = input()
print(encrypt(c_str1, c_in1))
elif state == 'd':
print("please enter the str that you want to decrypt :... ")
c_str = input()
print("\nplease enter the key (e.x. 1 to 52):... ")
c_in = int(input())
print(decrypt(c_str, c_in ))
I have the following code:
I am getting the error in counts.Item(value) = 1.
Set xmlNodeList = xmlEncounter.documentElement.selectNodes("//BillingLIne/Receipts")
If xmlNodeList.length > 1 Then
For i_Loop1 = 1 To xmlNodeList.length
strserviceChecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("ServiceID").nodeValue
Id1tobechecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("Receptid1").nodeValue
Id2tobechecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("Receptid2").nodeValue
Id3tobechecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("Receptid3").nodeValue
Id4tobechecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("Receptid4").nodeValue
Next i_Loop1
End If
Dim value As Variant
Dim counts As Collection
Set counts = New Collection
For Each value In strserviceChecked_GL
If Not Exists(counts,value) Then
counts.Item(value) = 1
Else
counts.Item(value) = counts.Item(value) + 1
End If
Next
Public Function Exists(ByVal oCol As Collection, ByVal vKey As Variant) As Boolean
On Error Resume Next
oCol.Item vKey
Exists = (Err.Number = 0)
Err.Clear
End Function
When a collection has no item for a key, you need to add one, and give it a value as follows.
For Each value In strserviceChecked_GL
If Not Exists(counts,value) Then
' Key 'value' is not in 'counts' collection.
' Add key 'value', and give it the value 1.
counts.Add 1, CStr(value)
'counts.Item(value) = 1
Else
counts.Item(value) = counts.Item(value) + 1
End If
Next
I have a query against a UDF where I want to allow the user to pass in either ALL or a specific EType.
If they pass in ALL, I want to accept all ETypes where it is not null.
I have searched thru SO for examples and not seem to meet my particular situation.
Where am I going wrong?
Declare
#company varchar(4),
#charge_cov bit,
#EType varchar(8);
set #company = '123'
set #charge_cov =1
set #EType = 'ALL'
select e.emp_id,
dbo.format_emp_number(pd.EN) as EN,
dbo.format_emp_number(pd.MEN) as MEN,
pd.EType
from dbo.employee_payroll_data(NULL) pd
inner join employee e on (e.emp_id=pd.emp_id)
where pd.EType = case when #EType='ALL' then pd.EType
else #EType ) END
and pd.EType is not null
and e.emp_number is not null
and e.charge_cov = 1
and lc.pr_co_code = #company
Try below code:
WHERE (((1 = (CASE WHEN #EType = 'ALL' THEN 1 ELSE 0 END)))
OR ((pd.Etype = (CASE WHEN #EType <> 'ALL' THEN #EType ELSE '' END))))
AND pd.Etype IS NOT NULL
I am trying to replicate a tables from production into the data warehouse. There are columns that I don't want the transactions for when an update is performed only on those columns. I was under the impression that the COLSEXCEPT command is what I needed to use
(
https://docs.oracle.com/goldengate/1212/gg-winux/GWURF/gg_parameters160.htm#GWURF546
{COLS | COLSEXCEPT} (column_list) Selects or excludes columns for processing.
TABLE
)
In my table the BL_ARREARS_IND column needs to be excluded since it is not in my target table. When I update only the BL_ARREARS_IND column in the source it is still logging the transaction in turn sending it to the target server.
I have an extract and a pump set up.
EXTRACT extbill
SETENV (ORACLE_SID=******)
SETENV (ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1)
USERID *****, PASSWORD *****
EXTTRAIL /u01/dwdev/oggdev/product/12.1.2/oggcore_2/dirdat/lb
TRANLOGOPTIONS ASMUSER SYS#ASM8, ASMPASSWORD ******
TABLE tmp.bill, &
KEYCOLS(ACCT_ID, BILL_SEQ_NO), &
**COLSEXCEPT(BL_ARREARS_IND);**
DISCARDFILE ./dwdev_ggdev_bill.dsc, APPEND
DiscardRollover at 02:00 ON SUNDAY
EXTRACT pumpbill
RMTHOST tst.corp.intranet, MGRPORT 7812
RMTTRAIL /u01/dwtst/oggdev/product/12.1.2/oggcore_2/dirdat/rb
TABLE tmp.bill **COLSEXCEPT(BL_ARREARS_IND);**
What am I missing?
I misunderstood the COLSEXCEPT command. I thought a transaction would only be created if a change was made to a field that was not in the COLSEXCEPT list. It still creates a transaction, but just doesn't send those fields to the target database (still not sure why you would create a transaction to changes to fields you are excluding).
I'm sure there is a better way, but I was able to get it to work using what I call a workaround by applying a filter to the table in the extract. This was a cumbersome process because the table has 82 fields. Had to compare the BEFORE image to the AFTER image for all of the other 81 fields that I do need.
When you have this many arguments in a FILTER you have to increase the FUNCTIONSTACKSIZE to accomodate (which in my case required a DBA to make the change).
I know there has to be a better way to handle this, but here is the code that worked for me:
TABLE tmp.bill, KEYCOLS(ACCT_ID, BILL_SEQ_NO), COLSEXCEPT(BL_ARREARS_IND),
FILTER(ON UPDATE,((#BEFORE(ACCT_ID) <> #AFTER(ACCT_ID)) or (#BEFORE(BILL_SEQ_NO) <> #AFTER(BILL_SEQ_NO)) or (#BEFORE(ACTUAL_BALANCE_AMT) <> #AFTER(ACTUAL_BALANCE_AMT)) or (#STREQ(#BEFORE(AFTER_CYCLE_CHG_IND),#AFTER(AFTER_CYCLE_CHG_IND)) = 0) or (#BEFORE(AGGREGATION_ID) <> #AFTER(AGGREGATION_ID)) or (#STREQ(#BEFORE(APPLICATION_ID),#AFTER(APPLICATION_ID)) = 0) or (#STREQ(#BEFORE(BANK_ACCOUNT_NO),#AFTER(BANK_ACCOUNT_NO)) = 0) or (#STREQ(#BEFORE(BANK_CODE),#AFTER(BANK_CODE)) = 0) or (#STREQ(#BEFORE(BAN_STATUS),#AFTER(BAN_STATUS)) = 0) or (#STREQ(#BEFORE(BAN_STATUS_DATE),#AFTER(BAN_STATUS_DATE)) = 0) or (#BEFORE(BF_ADJ) <> #AFTER(BF_ADJ)) or (#STREQ(#BEFORE(BF_BTN),#AFTER(BF_BTN)) = 0) or (#BEFORE(BF_CALL_CHG) <> #AFTER(BF_CALL_CHG)) or (#BEFORE(BF_IMM_ADJ) <> #AFTER(BF_IMM_ADJ)) or (#BEFORE(BF_MON_SRV_CHG) <> #AFTER(BF_MON_SRV_CHG)) or (#BEFORE(BF_ONE_TIME_CRG) <> #AFTER(BF_ONE_TIME_CRG)) or (#BEFORE(BF_TAXS) <> #AFTER(BF_TAXS)) or (#STREQ(#BEFORE(BILLING_METHOD),#AFTER(BILLING_METHOD)) = 0) or (#STREQ(#BEFORE(BILL_CONF_STATUS),#AFTER(BILL_CONF_STATUS)) = 0) or (#STREQ(#BEFORE(BILL_DATE),#AFTER(BILL_DATE)) = 0) or (#STREQ(#BEFORE(BILL_DUE_DATE),#AFTER(BILL_DUE_DATE)) = 0) or (#STREQ(#BEFORE(BILL_STATUS_DATE),#AFTER(BILL_STATUS_DATE)) = 0) or (#STREQ(#BEFORE(BL_BAL_HANDLE_IND),#AFTER(BL_BAL_HANDLE_IND)) = 0) or (#STREQ(#BEFORE(CARRY_OVER_IND),#AFTER(CARRY_OVER_IND)) = 0) or (#BEFORE(CH_BAL_CHGS) <> #AFTER(CH_BAL_CHGS)) or (#STREQ(#BEFORE(CREDIT_CARD_NO),#AFTER(CREDIT_CARD_NO)) = 0) or (#STREQ(#BEFORE(CREDIT_CARD_TYPE),#AFTER(CREDIT_CARD_TYPE)) = 0) or (#STREQ(#BEFORE(CR_CARD_AUTH_CODE),#AFTER(CR_CARD_AUTH_CODE)) = 0) or (#STREQ(#BEFORE(CR_CARD_EXP_DATE),#AFTER(CR_CARD_EXP_DATE)) = 0) or (#BEFORE(CURR_CHARGE_AMT) <> #AFTER(CURR_CHARGE_AMT)) or (#BEFORE(CURR_CREDIT_AMT) <> #AFTER(CURR_CREDIT_AMT)) or (#BEFORE(CURR_OC_CHRG_AMT) <> #AFTER(CURR_OC_CHRG_AMT)) or (#BEFORE(CURR_RC_CHRG_AMT) <> #AFTER(CURR_RC_CHRG_AMT)) or (#BEFORE(CURR_UC_CHRG_AMT) <> #AFTER(CURR_UC_CHRG_AMT)) or (#STREQ(#BEFORE(CYCLE_CLOSE_DATE),#AFTER(CYCLE_CLOSE_DATE)) = 0) or (#BEFORE(CYCLE_CODE) <> #AFTER(CYCLE_CODE)) or (#BEFORE(CYCLE_RUN_MONTH) <> #AFTER(CYCLE_RUN_MONTH)) or (#BEFORE(CYCLE_RUN_YEAR) <> #AFTER(CYCLE_RUN_YEAR)) or (#BEFORE(DEPOSIT_PAID_AMT) <> #AFTER(DEPOSIT_PAID_AMT)) or (#BEFORE(DEPOSIT_REQ_AMT) <> #AFTER(DEPOSIT_REQ_AMT)) or (#STREQ(#BEFORE(DL_SERVICE_CODE),#AFTER(DL_SERVICE_CODE)) = 0) or (#BEFORE(DL_UPDATE_STAMP) <> #AFTER(DL_UPDATE_STAMP)) or (#BEFORE(FGN_COUNTY_TAX_AMT) <> #AFTER(FGN_COUNTY_TAX_AMT)) or (#BEFORE(FGN_FED_TAX_AMT) <> #AFTER(FGN_FED_TAX_AMT)) or (#BEFORE(FGN_LOCAL_TAX_AMT) <> #AFTER(FGN_LOCAL_TAX_AMT)) or (#BEFORE(FGN_STATE_TAX_AMT) <> #AFTER(FGN_STATE_TAX_AMT)) or (#BEFORE(FREE_MINUTE_STATUS) <> #AFTER(FREE_MINUTE_STATUS)) or (#BEFORE(LATE_PYM_BASE_AMT) <> #AFTER(LATE_PYM_BASE_AMT)) or (#BEFORE(MASTER_BAN) <> #AFTER(MASTER_BAN)) or (#BEFORE(MB_BILL_SEQ_NO) <> #AFTER(MB_BILL_SEQ_NO)) or (#BEFORE(NM_ADR_LINK_SEQ_NO) <> #AFTER(NM_ADR_LINK_SEQ_NO)) or (#BEFORE(NON_TELECOM_AMT) <> #AFTER(NON_TELECOM_AMT)) or (#BEFORE(NUM_OF_PRODUCTS) <> #AFTER(NUM_OF_PRODUCTS)) or (#BEFORE(OPERATOR_ID) <> #AFTER(OPERATOR_ID)) or (#BEFORE(PAST_DUE_AMT) <> #AFTER(PAST_DUE_AMT)) or (#STREQ(#BEFORE(PAYMENT_METHOD),#AFTER(PAYMENT_METHOD)) = 0) or (#BEFORE(PAY_ARR_AMT_DUE) <> #AFTER(PAY_ARR_AMT_DUE)) or (#BEFORE(PAY_ARR_AMT_REM) <> #AFTER(PAY_ARR_AMT_REM)) or (#STREQ(#BEFORE(PRD_CVRG_END_DATE),#AFTER(PRD_CVRG_END_DATE)) = 0) or (#STREQ(#BEFORE(PRD_CVRG_STRT_DATE),#AFTER(PRD_CVRG_STRT_DATE)) = 0) or (#BEFORE(PREV_BALANCE_AMT) <> #AFTER(PREV_BALANCE_AMT)) or (#STREQ(#BEFORE(PRODUCTION_DATE),#AFTER(PRODUCTION_DATE)) = 0) or (#STREQ(#BEFORE(PRODUCTION_REQUEST),#AFTER(PRODUCTION_REQUEST)) = 0) or (#STREQ(#BEFORE(PRODUCTION_TYPE),#AFTER(PRODUCTION_TYPE)) = 0) or (#BEFORE(PRODUCTS_NUM_CALLS) <> #AFTER(PRODUCTS_NUM_CALLS)) or (#BEFORE(PRODUCTS_NUM_MINS) <> #AFTER(PRODUCTS_NUM_MINS)) or (#BEFORE(PYM_RECEIVED_AMT) <> #AFTER(PYM_RECEIVED_AMT)) or (#STREQ(#BEFORE(SYS_CREATION_DATE),#AFTER(SYS_CREATION_DATE)) = 0) or (#STREQ(#BEFORE(SYS_UPDATE_DATE),#AFTER(SYS_UPDATE_DATE)) = 0) or (#BEFORE(TAX_FED_AMT) <> #AFTER(TAX_FED_AMT)) or (#BEFORE(TAX_FED_USF_AMT) <> #AFTER(TAX_FED_USF_AMT)) or (#BEFORE(TAX_LOC_AMT) <> #AFTER(TAX_LOC_AMT)) or (#BEFORE(TAX_ROAM_AIR) <> #AFTER(TAX_ROAM_AIR)) or (#BEFORE(TAX_ROAM_SRV_CHARGE) <> #AFTER(TAX_ROAM_SRV_CHARGE)) or (#BEFORE(TAX_ROAM_TOLL) <> #AFTER(TAX_ROAM_TOLL)) or (#BEFORE(TAX_STT_AMT) <> #AFTER(TAX_STT_AMT)) or (#BEFORE(TELECOM_AMT) <> #AFTER(TELECOM_AMT)) or (#BEFORE(TOTAL_BILLED_ADJUST) <> #AFTER(TOTAL_BILLED_ADJUST)) or (#BEFORE(TOTAL_BILLED_CHARGE) <> #AFTER(TOTAL_BILLED_CHARGE)) or (#BEFORE(TOTAL_COUNTY_TAX) <> #AFTER(TOTAL_COUNTY_TAX)) or (#BEFORE(TOTAL_DUE_AMT) <> #AFTER(TOTAL_DUE_AMT)) or (#BEFORE(TOTAL_TAX_FEES) <> #AFTER(TOTAL_TAX_FEES))));
That code wasn't able to compare nulls. I came up with this macro which gave me the right output.
Filename: check_col.mac
Contents:
MACRO #check_col
PARAMS (#ICOL)
BEGIN
(
(0 = #IF (#COLTEST (#BEFORE(#ICOL), NULL, MISSING),0,1) AND 1 = #IF (#COLTEST (#ICOL, NULL, MISSING), 0, 1))
OR
(1 = #IF (#COLTEST(#BEFORE(#ICOL), NULL, MISSING), 0, 1) AND 0 = #IF (#COLTEST (#ICOL, NULL, MISSING), 0, 1))
OR
(0 = #STREQ(#BEFORE(#ICOL),#ICOL))
)
END;
You can use this macro in the INC file for the mapping like the below:
INCLUDE dirprm/check_col.mac
TABLE S1.T1, KEYCOLS(COL1, COL2), COLSEXCEPT(COL123), FILTER(ON UPDATE,(#check_col(COL3) or #check_col(COL4));
If you map more than 5 columns in this fashion, the code will throw a STACK SIZE NOT ENOUGH error, FUNCTIONSTACKSIZE = 5000 solves it. Let me know what negative effects this param has got.