Re: Sybase SQL interface

jredford@lehman.com
Tue, 24 Jan 95 09:14:40 -0500

> From: glenc@netcom.com (Glen Collins)
> Subject: Sybase SQL interface
>
>
> I was wondering if there was an interface out there for an SQL
> database. I would like to be able to connect "say with a Sybase Server" and
> retrieve info from the dbase. ANYONE?

I wrote what could loosely be called an interface, but have never had
cause to fully complete or document it. It works and it is fairly
simple. Call 'new' to make a 'db' object. Said object has a method
'sql' which takes a textual string (of SQL) as a paramater & returns
the results of executing it. Also the object has the method 'sp' which
takes the name of a stored procedure as its first argument, and
arguments to the sproc in a tuple as its second argument.

sql returns a list of results, where a result is a list of rows, and a
row is a tuple of fields, where a field is a basic sybase data type.
sp returns a tuple where the first value is the return value of the
sproc, and the second value is the same format as sql returns.

Flaws: No support for money or datetime types, not to mention blobs
and other less common types.

Python blocks waiting for all results of a query. This is not
appropriate for all applications.

Also there is the flaw that I dont support this, but I have never
heard of a bug either. If anyone improves this code, please let me
know.

Example:

import sybase

db = sybase.new(user,passwd,server)
result = db.sql("select * from Foo")
(code,result) = db.sp("sp_help",("Foo",))

Code:

begin 600 sybasemodule.c
M(VEN8VQU9&4@/'-T9&EO+F@^"@HC:6YC;'5D92 \<WEB9G)O;G0N:#X*(VEN
M8VQU9&4@/'-Y8F1B+F@^"@HC:6YC;'5D92 \4'DO86QL;V)J96-T<RYH/@HC
M:6YC;'5D92 \4'DO;6]D<W5P<&]R="YH/@H*"G-T871I8R!O8FIE8W0@*E-Y
M8F%S945R<F]R.PDO*B!E>&-E<'1I;VX@<WEB87-E+F5R<F]R("HO"@H*='EP
M961E9B!S=')U8W0@>PH@(" @(" @($]"7TA%040*"4Q/1TE.4D5#("IL;V=I
M;CL)+RH@;&]G:6X@<F5C;W)D("HO"@E$0E!23T-%4U,@*F1B<')O8SL)+RH@
M;&]G:6X@<F5C;W)D("HO"GT@<WEB9&)O8FIE8W0["@IE>'1E<FX@='EP96]B
M:F5C="!3>6)$8G1Y<&4[("\J($9O<G=A<F0@*B\*"@IS=&%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 ]/2!3
M54-#145$*2!["B @(" @(&QI<W0@/2!N97=L:7-T;V)J96-T*# I.PH@(" @
M("!C;VQS(#T@9&)N=6UC;VQS*&1B<"D["B @(" @(&9M=" ]("AI;G0@*BEM
M86QL;V,H<VEZ96]F*&EN="D@*B!C;VQS*3L*(" @(" @9F]R("AI(#T@,3L@
M:2 \/2!C;VQS.R!I*RLI('L*"7-W:71C:"AD8F-O;'1Y<&4H9&)P+"!I*2D@
M>PH)8V%S92!364)#2$%2.@H)("!F;71;:2TQ72 ](%-90D-(05(["@D@(&)R
M96%K.PH)8V%S92!364))3E0Q.@H)("!F;71;:2TQ72 ](%-90DE.5#$["@D@
M(&)R96%K.PH)8V%S92!364))3E0R.@H)("!F;71;:2TQ72 ](%-90DE.5#([
M"@D@(&)R96%K.PH)8V%S92!364))3E0T.@H)("!F;71;:2TQ72 ](%-90DE.
M5#0["@D@(&)R96%K.PH)8V%S92!364)&3%0X.@H)("!F;71;:2TQ72 ](%-9
M0D9,5#@["@D@(&)R96%K.PH)?0H@(" @("!]"B @(" @('=H:6QE("AD8FYE
M>'1R;W<H9&)P*2 A/2!.3U]-3U)%7U)/5U,I('L*"71U<&QE(#T@;F5W='5P
M;&5O8FIE8W0H8V]L<RD["@EF;W(@*&D@/2 Q.R!I(#P](&-O;',[(&DK*RD@
M>PH)("!S=VET8V@H9FUT6VDM,5TI('L*"2 @8V%S92!364)#2$%2.@H)(" @
M(&\@/2!N97=S:7IE9'-T<FEN9V]B:F5C="@H8VAA<B J*61B9&%T82AD8G L
M(&DI+"!D8F1A=&QE;BAD8G L(&DI*3L*"2 @("!S971T=7!L96ET96TH='5P
M;&4L(&DM,2P@;RD["@D@(" @8G)E86L["@D@(&-A<V4@4UE"24Y4,3H*"2 @
M("!O(#T@;F5W:6YT;V)J96-T*"HH*&-H87(@*BED8F1A=&$H9&)P+"!I*2DI
M.PH)(" @('-E='1U<&QE:71E;2AT=7!L92P@:2TQ+"!O*3L*"2 @("!B<F5A
M:SL*"2 @8V%S92!364))3E0R.@H)(" @(&\@/2!N97=I;G1O8FIE8W0H*B@H
M<VAO<G0@*BED8F1A=&$H9&)P+"!I*2DI.PH)(" @('-E='1U<&QE:71E;2AT
M=7!L92P@:2TQ+"!O*3L*"2 @("!B<F5A:SL*"2 @8V%S92!364))3E0T.@H)
M(" @(&\@/2!N97=I;G1O8FIE8W0H*B@H:6YT("HI9&)D871A*&1B<"P@:2DI
M*3L*"2 @("!S971T=7!L96ET96TH='5P;&4L(&DM,2P@;RD["@D@(" @8G)E
M86L["@D@(&-A<V4@4UE"1DQ4.#H*"2 @("!O(#T@;F5W9FQO871O8FIE8W0H
M*B@H9&]U8FQE("HI9&)D871A*&1B<"P@:2DI*3L*"2 @("!S971T=7!L96ET
M96TH='5P;&4L(&DM,2P@;RD["@D@(" @8G)E86L["@D@('T*"7T*"6%D9&QI
M<W1I=&5M*&QI<W0L='5P;&4I.PH@(" @("!]"B @(" @(&9R964H9FUT*3L*
M(" @(" @861D;&ES=&ET96TH<F5S=6QT<RQL:7-T*3L*(" @('T*("!]"B @
M<F5T=7)N("AR97-U;'1S*3L*?0H*<W1A=&EC(&]B:F5C= H@("IS>6)D8E]S
M<6P@*'-E;&8L(&%R9W,I"F]B:F5C=" J<V5L9CL*;V)J96-T("IA<F=S.PI[
M"B @8VAA<B J<W%L.PH@($1"4%)/0T534R J9&)P.PH*("!D8G @/2 H*'-Y
M8F1B;V)J96-T("HI<V5L9BDM/F1B<')O8SL*("!E<G)?8VQE87(@*"D["B @
M:68@*"%G971A<F=S("AA<F=S+" B<R(L("9S<6PI*2!["B @("!R971U<FX@
M3E5,3#L*("!]"B @9&)C86YC96PH9&)P*3L*("!D8F-M9"AD8G L('-Q;"D[
M"B @9&)S<6QE>&5C*&1B<"D["B @<F5T=7)N(&=E=')E<W5L=',H9&)P*3L*
M?0H*<W1A=&EC(&]B:F5C= H@("IS>6)D8E]S<" H<V5L9BP@87)G<RD*;V)J
M96-T("IS96QF.PIO8FIE8W0@*F%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P87)G*2D["B @(" @('T@96QS
M92!["@EE<G)?<V5T<W1R("A3>6)A<V5%<G)O<BP@(D-O=6QD(&YO="!H86YD
M;&4@<&%R86UA=&5R<R!T;R!P<F]C961U<F4N(BD["@ER971U<FX@3E5,3#L*
M(" @(" @?0H@(" @?0H@('T@96QS92!I9B H<W!A<F=S("$]($YO;F4I('L*
M(" @(&5R<E]S971S='(@*%-Y8F%S945R<F]R+" B0V]U;&0@;F]T(&AA;F1L
M92!P87)A;6%T97)S('1O('!R;V-E9'5R92XB*3L*(" @(')E='5R;B!.54Q,
M.PH@('T*("!D8G)P8W-E;F0H9&)P*3L*("!D8G-Q;&]K*&1B<"D["@H@(')E
M<W5L=',@/2!G971R97-U;'1S*&1B<"D["B @<F5T<W1A='5S(#T@9&)R971S
M=&%T=7,H9&)P*3L*"B @<B ](&UK=F%L=64H(BAI3RDB+"!R971S=&%T=7,L
M(')E<W5L=',I.PH@($1%0U)%1BAR97-U;'1S*3L*("!R971U<FX@*'(I.PI]
M"@H*<W1A=&EC('-T<G5C="!M971H;V1L:7-T('-Y8F1B7VUE=&AO9'-;72 ]
M('L*("![(G-Q;"(L(" @(" @("!S>6)D8E]S<6Q]+ H@('LB<W B+" @(" @
M(" @('-Y8F1B7W-P?2P*("![3E5,3"P@(" @(" @("!.54Q,?0D)+RH@<V5N
M=&EN96P@*B\*?3L*"G-T871I8R!V;VED"G-Y8F1B7V1E86QL;V,H<RD*(" @
M("!S>6)D8F]B:F5C=" J<SL*>PH@(&1B;&]G:6YF<F5E*',M/FQO9VEN*3L*
M("!D8F-L;W-E*',M/F1B<')O8RD["B @1$5,*',I.PI]"@IS=&%T:6,@;V)J
M96-T("H*<WEB9&)?9V5T871T<BAS+"!N86UE*0H@(" @('-Y8F1B;V)J96-T
M("IS.PH@(" @(&-H87(@*FYA;64["GL*("!R971U<FX@9FEN9&UE=&AO9"AS
M>6)D8E]M971H;V1S+" H;V)J96-T("HI(',L(&YA;64I.PI]"@H*='EP96]B
M:F5C="!3>6)$8G1Y<&4@/2!["B @(" @(" @3T)?2$5!1%])3DE4*"94>7!E
M='EP92D*(" @(" @(" P+ H@(" @(" @(")S>6)D8B(L"B @(" @(" @<VEZ
M96]F*'-Y8F1B;V)J96-T*2P*(" @(" @(" P+ H@(" @(" @('-Y8F1B7V1E
M86QL;V,L"0DO*G1P7V1E86QL;V,J+PH@(" @(" @(# L"0D)+RIT<%]P<FEN
M="HO"B @(" @(" @<WEB9&)?9V5T871T<BP)"2\J='!?9V5T871T<BHO"B @
M(" @(" @,"P)"0DO*G1P7W-E=&%T='(J+PH@(" @(" @(# L"0D)+RIT<%]C
M;VUP87)E*B\*(" @(" @(" P+ D)"2\J='!?<F5P<BHO"B @(" @(" @,"P)
M"0DO*G1P7V%S7VYU;6)E<BHO"B @(" @(" @,"P)"0DO*G1P7V%S7W-E<75E
M;F-E*B\*(" @(" @(" P+ D)"2\J='!?87-?;6%P<&EN9RHO"GT["@H*"@H*
M+RH@34]$54Q%($953D-424].4SH@<WEB87-E("HO"@IS=&%T:6,@;V)J96-T
M"B @*G-Y8F%S95]N97<@*'-E;&8L(&%R9W,I"F]B:F5C=" J<V5L9CL)"2\J
M($YO="!U<V5D("HO"F]B:F5C=" J87)G<SL*>PH@(&-H87(@*G5S97(L("IP
M87-S=V0L("IS97)V97(["B @;V)J96-T("ID8CL*"B @97)R7V-L96%R("@I
M.PH@(&EF("@A9V5T87)G<R H87)G<RP@(BAZ>GHI(BP@)G5S97(L("9P87-S
M=V0L("9S97)V97(I*2!["B @("!R971U<FX@3E5,3#L*("!]"B @9&(@/2 H
M;V)J96-T("HI(&YE=W-Y8F1B;V)J96-T*'5S97(L('!A<W-W9"P@<V5R=F5R
M*3L*("!I9B H(61B*2!["B @(" O*B!86%@@4VAO=6QD(&)E('-E='1I;F<@
M<V]M92!E<G)S='(@<W1U9F8@:&5R92!B87-E9"!O;B!S>6)A<V4@97)R;W)S
M("HO"B @("!E<G)?<V5T<W1R("A3>6)A<V5%<G)O<BP@(D-O=6QD(&YO="!O
M<&5N(&-O;FYE8W1I;VX@=&\@<V5R=F5R+B(I.PH@(" @<F5T=7)N($Y53$P[
M"B @?0H@(')E='5R;B!D8CL*?0H*"B\J($QI<W0@;V8@;6]D=6QE(&9U;F-T
M:6]N<R J+PIS=&%T:6,@<W1R=6-T(&UE=&AO9&QI<W0@<WEB87-E7VUE=&AO
M9'-;73T*>PH@('LB;F5W(BP@<WEB87-E7VYE=WTL"B @>TY53$PL($Y53$Q]
M"0D)+RH@<V5N=&EN96P@*B\*?3L*"B\J($UO9'5L92!I;FET:6%L:7-A=&EO
M;B J+PIV;VED(&EN:71S>6)A<V4@*"D*>PH@(&]B:F5C=" J;2P@*F0["@H@
M("\J($-R96%T92!T:&4@;6]D=6QE(&%N9"!A9&0@=&AE(&9U;F-T:6]N<R J
M+PH@(&T@/2!I;FET;6]D=6QE("@B<WEB87-E(BP@<WEB87-E7VUE=&AO9',I
M.PH@("\J($%D9"!S;VUE('-Y;6)O;&EC(&-O;G-T86YT<R!T;R!T:&4@;6]D
M=6QE("HO"B @9" ](&=E=&UO9'5L961I8W0@*&TI.PH@(%-Y8F%S945R<F]R
M(#T@;F5W<W1R:6YG;V)J96-T("@B<WEB87-E+F5R<F]R(BD["B @:68@*%-Y
M8F%S945R<F]R(#T]($Y53$P@?'P@9&EC=&EN<V5R=" H9"P@(F5R<F]R(BP@
M4WEB87-E17)R;W(I("$](# I('L*(" @(&9A=&%L("@B8V%N)W0@9&5F:6YE
M('-Y8F%S92YE<G)O<B(I.PH@('T*(" O*B!#:&5C:R!F;W(@97)R;W)S("HO
M"B @:68@*&5R<E]O8V-U<G)E9" H*2E["B @("!F871A;" H(F-A;B=T(&EN
@:71I86QI>F4@;6]D=6QE('-Y8F%S92(I.PH@('T*?0IA

end

--
John Redford (AKA GArrow) | 3,600 hours of tape.
jredford@lehman.com       | 5 cans of Scotchguard.