the code is not returning any value and the code is being stored in user defined function instead of stored procedure - eclipse

CREATE PROCEDURE bank(
in bk_cd_in CHAR( 4 ) ,
out bk_cd_out CHAR( 4 ) ,
out bk_nm CHAR( 40 ) ,
out brh_cd CHAR( 8 ) ,
out bak_hnm CHAR( 40 ) ,
out ur_cd CHAR(18),
out updt DATE,
out updt_flag CHAR( 1 ) ,
out brh_nm CHAR( 40 ) ,
out cty_nm CHAR( 40 ) )
SELECT bank_cd, bank_nm, branch_cd, bank_hnm, user_cd, update_dt, update_flag, branch_nm, city_nm
FROM bankmst
WHERE bank_cd = bk_cd_in
into bk_cd_out, bk_nm, brh_cd, bak_hnm, ur_cd, updt, updt_flag, brh_nm, cty_nm ;
the calling code written in jsp the out parametres are empty and on running the jsp page the error : com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'b1' in 'field list' ended
try
{
cs = con.prepareCall("{call bank(?,?,?,?,?,?,?,?,?,?)}");
String s1 = para;
cs.setString(1,para);
cs.registerOutParameter(2, java.sql.Types.VARCHAR);
cs.registerOutParameter(3, java.sql.Types.VARCHAR);
cs.registerOutParameter(4, java.sql.Types.CHAR);
cs.registerOutParameter(5, java.sql.Types.CHAR);
cs.registerOutParameter(6, java.sql.Types.CHAR);
cs.registerOutParameter(7, java.sql.Types.DATE);
cs.registerOutParameter(8, java.sql.Types.CHAR);
cs.registerOutParameter(9, java.sql.Types.CHAR);
cs.registerOutParameter(10, java.sql.Types.CHAR);
cs.registerOutParameter(11, java.sql.Types.INTEGER);
rs = cs.executeQuery();
out.println("\nexecuted 3\n");
String b1 = cs.getString(2);
String b2 = cs.getString(3);
String b3 = cs.getString(4);
String b4 = cs.getString(5);
String b5 = cs.getString(6);
java.util.Date b6 = cs.getDate(7);
String b7 = cs.getString(8);
String b8 = cs.getString(9);
String b9 = cs.getString(10);
System.out.println(b1);
System.out.println(b2);
System.out.println(b3);
System.out.println(b4);
System.out.println(b5);
System.out.println(b6);
System.out.println(b7);
System.out.println(b8);
System.out.println(b9);
}
..I am using eclipse 3.6 and the code is written in mysql 5.1

Related

Integer encoding format

I've run across some PIN encoding which I'm trying to figure out so I can improve upon a web application used at my place of work.
When I reset users' PINs (in this case, just my own for testing purposes), I'm seeing the following:
PIN VALUE
000000 = 7F55858585858585
111111 = 7F55868686868686
222222 = 7F55878787878787
999999 = 7F558E8E8E8E8E8E
000001 = 7F01313131313132
000011 = 7F55858585858686
000111 = 7F01313131323232
001111 = 7F55858586868686
011111 = 7F01313232323232
000002 = 7F02323232323234
100000 = 7F01323131313131
111112 = 7F03343434343435
123456 = 7F0738393A3B3C3D
654321 = 7F073D3C3B3A3938
1357924680 = 7F01323436383A3335373931
1111111111 = 7F5586868686868686868686
1234567890 = 7F0132333435363738393A31
It's clearly just hex, and always starts with 7F (1111111 or 127), but I'm not seeing a pattern for how the next two characters are chosen. Those two characters seem to be the determining value for converting the PIN.
For example:
000000 = 7F 55 858585858585
7F (hex) = 127 (dec) or 1111111 (bin) ## appears to not be used in the calculation?
55 (hex) = 85 (dec) or 1010101 (bin)
0 (PIN) + 85 = 85
000000 = 858585858585
111111 = 7F 55 868686868686
7F (hex) = 127 (dec) or 1111111 (bin) ## appears to not be used in the calculation?
55 (hex) = 85 (dec)
1 (PIN) + 85 = 86
111111 = 868686868686
But then also:
1357924680 = 7F 01 323436383A3335373931
01 (hex) = 31 (dec) ?
1 (PIN) + 31 = 32
1357924680 = 323436383A3335373931
Any help pointing me in the right direction would be greatly appreciated.
I don't see enough data in your minimal reproducible example to uncover an algorithm how the pinshift value should be determined (supplied to the pin_to_hex function). A random value is used in the following solution:
def hex_to_pin( pinhex: str) -> list:
'''
decode a PIN from a particular hexadecimal-formatted string
hex_to_pin('7F0738393A3B3C3D')
inverse of the "pin_to_hex" function (any of the following):
hex_to_pin(pin_to_hex('123456', 7))
pin_to_hex(*hex_to_pin('7F0738393A3B3C3D'))
'''
xxaux = bytes.fromhex(pinhex)
return [bytes([x - xxaux[1] for x in xxaux[2:]]).decode(),
xxaux[1]]
def pin_to_hex( pindec: str, pinshift: int, upper=False) -> str:
'''
encode a PIN to a particular hexadecimal-formatted string
pin_to_hex('123456', 7)
inverse of the "hex_to_pin" function (any of the following):
pin_to_hex(*hex_to_pin('7F0738393A3B3C3D'),True)
hex_to_pin(pin_to_hex('123456', 7))
'''
shift_ = max( 1, pinshift % 199) ## 134 for alpha-numeric PIN code
retaux = [b'\x7F', shift_.to_bytes(1, byteorder='big')]
for digit_ in pindec.encode():
retaux.append( (digit_ + shift_).to_bytes(1, byteorder='big'))
if upper:
return (b''.join(retaux)).hex().upper()
else:
return (b''.join(retaux)).hex()
def get_pin_shift( pindec: str) -> int:
'''
determine "pinshift" parameter for the "pin_to_hex" function
currently returns a random number
'''
return random.randint(1,198) ## (1,133) for alpha-numeric PIN code
hexes = [
'7F01323436383A3335373931',
'7F0738393A3B3C3D',
'7F558E8E8E8E8E8E'
]
print("hex_to_pin:")
maxlen = len( max(hexes, key=len))
deces = []
for xshex in hexes:
xsdec = hex_to_pin( xshex)
print( f"{xshex:<{maxlen}} ({xsdec[1]:>3}) {xsdec[0]}")
deces.append(xsdec[0])
import random
print("pin_to_hex:")
for xsdec in deces:
xsshift = get_pin_shift( xsdec)
xshex = pin_to_hex( xsdec, xsshift)
print( f"{xshex:<{maxlen}} ({xsshift:>3}) {xsdec}")
Output SO\71875753.py
hex_to_pin:
7F01323436383A3335373931 ( 1) 1357924680
7F0738393A3B3C3D ( 7) 123456
7F558E8E8E8E8E8E ( 85) 999999
pin_to_hex:
7f1041434547494244464840 ( 16) 1357924680
7f4e7f8081828384 ( 78) 123456
7f013a3a3a3a3a3a ( 1) 999999

to pass a variable from a method to the main body

I made a code to compare 2 times . The structure of the code constitutes of a main body getting the 2 times. A class and 2 methods are converting the times into second just to make an integer. The problem is that the variable showing the integer doesn't pass to the main body. The code is as follow.
class Time():
def __init__(self, other=None):
self.other = other
def comparison(self, other):
self.other = other
return other > self
def time_to_int(self, other):
self.other = other
other = self.hour * 3600 + self.minute * 60 + self.second
print( other )
start = Time()
start.hour = 2.0
start.minute = 87
start.second = 98
start_time = Time()
start.time_to_int( start_time )
end = Time()
end.hour = 3.0
end.minute = 87
end.second = 98
end_time = Time()
end.time_to_int( end_time )
print( start_time, end_time )
start_time.comparison( end_time )
The result is
12518.0
16118.0
<__main__.Time object at 0x7f9ca1854110> <__main__.Time object at 0x7f9ca18541d0>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-dc5298ddf4b1> in <module>()
31
32
---> 33 start_time.comparison(end_time)
34
<ipython-input-1-dc5298ddf4b1> in comparison(self, other)
5 def comparison(self, other):
6 self.other=other
----> 7 return other > self
8 def time_to_int(self, other):
9 self.other=other
TypeError: '>' not supported between instances of 'Time' and 'Time'
Your comparison method uses other > self, and the TypeError tells you that this is not defined. What's your question?

How to get the UTF-8 code from a single character in VBScript

I would like to get the UTF-8 Code of a character, have attempted to use streams but it doesn't seem to work:
Example: פ should give 16#D7A4, according to https://en.wikipedia.org/wiki/Pe_(Semitic_letter)#Character_encodings
Const adTypeBinary = 1
Dim adoStr, bytesthroughado
Set adoStr = CreateObject("Adodb.Stream")
adoStr.Charset = "utf-8"
adoStr.Open
adoStr.WriteText labelString
adoStr.Position = 0
adoStr.Type = adTypeBinary
adoStr.Position = 3
bytesthroughado = adoStr.Read
Msgbox(LenB(bytesthroughado)) 'gives 2
adoStr.Close
Set adoStr = Nothing
MsgBox(bytesthroughado) ' gives K
Note: AscW gives Unicode - not UTF-8
The bytesthroughado is a value of byte() subtype (see 1st output line) so you need to handle it in an appropriate way:
Option Explicit
Dim ss, xx, ii, jj, char, labelString
labelString = "ařЖפ€"
ss = ""
For ii=1 To Len( labelString)
char = Mid( labelString, ii, 1)
xx = BytesThroughAdo( char)
If ss = "" Then ss = VarType(xx) & " " & TypeName( xx) & vbNewLine
ss = ss & char & vbTab
For jj=1 To LenB( xx)
ss = ss & Hex( AscB( MidB( xx, jj, 1))) & " "
Next
ss = ss & vbNewLine
Next
Wscript.Echo ss
Function BytesThroughAdo( labelChar)
Const adTypeBinary = 1 'Indicates binary data.
Const adTypeText = 2 'Default. Indicates text data.
Dim adoStream
Set adoStream = CreateObject( "Adodb.Stream")
adoStream.Charset = "utf-8"
adoStream.Open
adoStream.WriteText labelChar
adoStream.Position = 0
adoStream.Type = adTypeBinary
adoStream.Position = 3
BytesThroughAdo = adoStream.Read
adoStream.Close
Set adoStream = Nothing
End Function
Output:
cscript D:\bat\SO\61368074q.vbs
8209 Byte()
a 61
ř C5 99
Ж D0 96
פ D7 A4
€ E2 82 AC
I used characters ařЖפ€ to demonstrate the functionality of your UTF-8 encoder (the alts8.ps1 PowerShell script comes from another project):
alts8.ps1 "ařЖפ€"
Ch Unicode Dec CP IME UTF-8 ? IME 0405/cs-CZ; CP852; ANSI 1250
a U+0061 97 …97… 0x61 a Latin Small Letter A
ř U+0159 345 …89… 0xC599 Å� Latin Small Letter R With Caron
Ж U+0416 1046 …22… 0xD096 Ð� Cyrillic Capital Letter Zhe
פ U+05E4 1508 …228… 0xD7A4 פ Hebrew Letter Pe
€ U+20AC 8364 …172… 0xE282AC â�¬ Euro Sign

Cryptic TypeError: 'decimal.Decimal' object cannot be interpreted as an integer

I am struggling to understand why this function apparently fails in the Jupyter Notebook, but not in the IPython shell:
def present_value( r, n, fv = None, pmt = None ):
'''
Function to compute the Present Value based on interest rate and
a given future value.
Arguments accepted
------------------
* r = interest rate,
which should be given in its original percentage, eg.
5% instead of 0.05
* n = number of periods for which the cash flow,
either as annuity or single flow from one present value
* fv = future value in dollars,
if problem is annuity based, leave this empty
* pmt = each annuity payment in dollars,
if problem is single cash flow based, leave this empty
'''
original_args = [r, n, fv, pmt]
dec_args = [Decimal( arg ) if arg != None
else arg
for arg in original_args
]
if dec_args[3] == None:
return dec_args[2] / ( ( 1 + ( dec_args[0] / 100 ) )**dec_args[1] )
elif dec_args[2] == None:
# annuity_length = range( 1, dec_args[1] + 1 )
# Not allowed to add a Decimal object
# with an integer and to use it
# in the range() function,
# so we dereference the integer from original_args
annuity_length = range( 1, original_args[1] + 1 )
# Apply discounting to each annuity payment made
# according to number of years left till end
all_compounded_pmt = [dec_args[3] * ( 1 / ( ( 1 + dec_args[0] / 100 ) ** time_left ) ) \
for time_left in annuity_length
]
return sum( all_compounded_pmt )
When I imported the module that this function resides in, named functions.py, using from functions import *, and then executed present_value(r=7, n=35, pmt = 11000), I got the error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-93-c1cc587f7e27> in <module>()
----> 1 present_value(r=7, n=35, pmt = 11000)
/path_to_file/functions.py in present_value(r, n, fv, pmt)
73 if dec_args[3] == None:
74 return dec_args[2]/((1 + (dec_args[0]/100))**dec_args[1])
---> 75
76 elif dec_args[2] == None:
77 # annuity_length = range(1, dec_args[1]+1)
TypeError: 'decimal.Decimal' object cannot be interpreted as an integer
but in the IPython shell, evaluating this function it works perfectly fine:
In [42]: functions.present_value(r=7, n=35, pmt = 11000)
Out[42]: Decimal('142424.39530474029537')
Can anyone please help me with this really confusing and obscure issue?

Visual Foxpro Data Grid based entry screen forms

I am having three tables first for Parties name, Second for Qualities and third for
storing purchase orders. At present I developed order entry form with text boxes.
It's difficult to enter order when I am having 10 or 20+ orders from one party in same date with different quality.
Now I want to make it in grid. First select date then Party and enter orders as many as you want. But I do not know how to do this in Visual Foxpro. I tried a lot to find some samples or examples but failed to find. One more thing I want to mention here that this is my only one form from my 4 forms app. I need to know how to do calculations in grids.
Please help.
In the VFP command window, open the Task Pane Manager and choose Solution Samples. Search for grid and you'll find a bunch of examples on using grids.
Something like this?
createtables()
ON ERROR
oForm = CREATEOBJECT("myform")
oForm.visible = .t.
READ EVENTS
DEFINE CLASS mygrid as grid
PROCEDURE init
this.top = 40
this.Left = 10
this.Width = 450
this.ColumnCount = 6
this.DeleteMark = .f.
this.RecordMark = .f.
this.RecordSource = "porders"
this.column1.ControlSource = this.RecordSource + ".podate"
this.column1.Header1.Caption = "PO Date"
this.column1.width = 75
this.column2.ControlSource = this.RecordSource + ".ponum"
this.column2.Header1.Caption = "PO Num"
this.column2.width = 65
this.column3.ControlSource = this.RecordSource + ".poparty"
this.column3.Header1.Caption = "Party"
this.column3.width = 65
this.column4.ControlSource = this.RecordSource + ".poqty"
this.column4.Header1.Caption = "Qty"
this.column4.width = 65
this.column5.ControlSource = this.RecordSource + ".poprice"
this.column5.Header1.Caption = "Price"
this.column5.width = 65
this.column6.addobject("oqualities", "myqualities")
this.column6.CurrentControl = "oqualities"
this.column6.width = 65
this.column6.sparse = .t.
this.column6.Header1.Caption = "Quality"
this.column6.ControlSource = this.RecordSource + ".poquality"
ENDPROC
ENDDEFINE
DEFINE class mycombo as combobox
PROCEDURE init
this.top = 10
this.left = 150
this.Style = 2
this.RowSource = "parties.name"
this.RowSourceType = 6
ENDPROC
PROCEDURE interactivechange
SELECT (this.Parent.oGrid.RecordSource)
lcVal = ["] + ALLTRIM(this.value) + ["]
SET FILTER TO ALLTRIM(poparty) = &lcVal
this.Parent.ogrid.refresh()
ENDPROC
ENDDEFINE
DEFINE class myqualities as combobox
PROCEDURE init
this.Style = 2
this.RowSource = "qualities.desc"
this.RowSourceType = 6
ENDPROC
ENDDEFINE
DEFINE CLASS mybutton as commandbutton
PROCEDURE init
LPARAMETERS tcMode
this.Caption = tcMode
this.Top = 250
this.Left = 10
ENDPROC
PROCEDURE click
IF this.Caption == "ADD"
IF EMPTY(ALLTRIM(this.Parent.oparties.value))
MESSAGEBOX("Please select party")
RETURN .f.
ENDIF
SELECT (this.Parent.ogrid.recordsource)
APPEND BLANK
replace podate WITH this.parent.odate.value, ;
ponum WITH INT(RAND()*100000), ;
poparty WITH this.Parent.oparties.value, ;
poqty WITH 1
this.Parent.ogrid.setfocus()
ENDIF
ENDPROC
ENDDEFINE
DEFINE CLASS mydate as TextBox
PROCEDURE init
this.Value = DATE()
this.Left = 10
this.Top = 10
ENDPROC
ENDDEFINE
DEFINE CLASS myform as form
PROCEDURE init
this.AddObject("ogrid", "mygrid")
this.AddObject("odate", "mydate")
this.AddObject("oparties", "mycombo")
this.AddObject("oAdd", "mybutton", "ADD")
this.ogrid.visible = .t.
this.oparties.visible = .t.
this.oAdd.visible = .t.
this.odate.visible = .t.
this.Height = 300
this.Width = 470
this.Visible = .t.
ENDPROC
ENDDEFINE
PROCEDURE createtables
IF !USED('parties')
CREATE TABLE parties FREE (name c(20))
INSERT INTO parties values("John")
INSERT INTO parties values("Richard")
INSERT INTO parties values("Melvin")
ENDIF
IF !USED('qualities')
CREATE TABLE qualities FREE (desc c(20))
INSERT INTO qualities values("GOOD")
INSERT INTO qualities values("BAD")
INSERT INTO qualities values("SMELLY")
ENDIF
IF !USED('porders')
CREATE TABLE porders FREE (ponum i, podate D, poparty c(20), poqty n(10,2), poprice n(10,2), poquality c(20))
ENDIF
ENDPROC