Skip to Content.
Sympa Menu

freetds - RE: [freetds] TDS_DONE_TOKEN (and others)

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddyz77 AT tin.it>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] TDS_DONE_TOKEN (and others)
  • Date: 01 May 2003 09:29:54 +0200

Il mer, 2003-04-30 alle 23:02, Lowden, James K ha scritto:
> > From: Frediano Ziglio [mailto:freddyz77 AT tin.it]
> > Sent: April 30, 2003 3:09 PM
> >
> > I putted some "FIXME ICONV" in query.c. Mainly some sizes are needed
> > before sending string...
>
> Thanks.
>
> > Also our library do not work with non ASCII extended charset.
> > It this a
> > problem? Some code require query parsing, so extended ascii charset
> > (even utf8) work,
>
> Not a problem in theory. We just need two TDSICONVINFO structures, one for
> UCS-2, and one for the server's character set.
>

However some action require to parse the client query, for example to
replace placeholders (?) with named parameters (@P0 or whatever)

> > ebcdici (how to write it?) not!
>
> See the iconv FAQ. Basically, it says: "EBCDIC? No!"
>
> > I renamed TDS_COMPLETED in TDS_IDLE and changed code in
> > query.c to test this state instead of "PENDING".
>
> Wow. That was quick!
>

grep is my friend :)

> > I also changed all server type define
> > to an enum. My intention is to use enum so compiler can provide better
> > warnings
>
> I like enum and think it's underused. Sometimes we're constrained; either
> because Sybase used #define, or because emum is 'int' bits wide (and so not
> appropriate for, say, a 2-byte status code in the TDS packet).
>

you can use syntax like
enum my_enum var:16;

> > Anyone know how to pass dynamic query to Sybase passing types? Can I
> > post a dynamic query like
> >
> > create proc my_proc @pippo int as ... ??
> >
> > In TDS7+ I do something like
> > sp_prepare @P1 out, '@pippo int', 'select @pippo', 1
> > sp_execute @P1, @param1, @param2 ...
>
> TDS 5.0 uses the TDS_DYNAMIC (0xE7) token. I doubt there's any support for
> dynamic queries in 4.2.
>
> With TDS_DYNAMIC, you send the statement text, then *ask* the server to
> describe the i/o parameters (i.e. types). To execute, you send TDS_DYNAMIC
> again ('type' TDS_DYN_EXEC (0x02)), followed by a bunch of parameter
> packets. Paramater names are not supported.
>
> IMHO, this is a sensible approach, but requires the server to do more work.
>

I know, but there are problem with image/text field...

These are capture from some test with binary_test (odbc test, trying to
insert binary to a field using prepared statement, reformatted for mail
problems)

Test 1 - cvs version with --enable-developing

Creating prepared statement
Sending packet @ 2003-05-01 08:54:58.727495
0000 0f 01 00 57 00 00 00 00-e7 4c 00 01 00 0a 67 70 |...W.... .L....gp|
0010 77 77 32 33 36 30 30 30-3d 00 63 72 65 61 74 65 |ww236000 =.create|
0020 20 70 72 6f 63 20 67 70-77 77 32 33 36 30 30 30 | proc gp ww236000|
0030 20 61 73 20 69 6e 73 65-72 74 20 69 6e 74 6f 20 | as inse rt into |
0040 23 62 69 6e 61 72 79 5f-74 65 73 74 20 76 61 6c |#binary_ test val|
0050 75 65 73 20 28 3f 29 |ues (?)|


Received header @ 2003-05-01 08:54:58.731371
0000 04 01 00 d8 00 00 00 00 |........|


Received packet @ 2003-05-01 08:54:58.731462
0000 e7 0d 00 20 00 0a 67 70-77 77 32 33 36 30 30 30 |... ..gp ww236000|
0010 e5 b4 00 de 0a 00 00 01-10 05 5a 5a 5a 5a 5a 00 |........ ..ZZZZZ.|
0020 01 00 95 00 41 6e 20 75-6e 74 79 70 65 64 20 76 |....An u ntyped v|
0030 61 72 69 61 62 6c 65 20-69 6e 20 74 68 65 20 50 |ariable in the P|
0040 52 45 50 41 52 45 20 73-74 61 74 65 6d 65 6e 74 |REPARE s tatement|
0050 20 27 67 70 77 77 32 33-36 30 30 30 27 20 69 73 | 'gpww23 6000' is|
0060 20 62 65 69 6e 67 20 72-65 73 6f 6c 76 65 64 20 | being r esolved |
0070 74 6f 20 61 20 54 45 58-54 20 6f 72 20 49 4d 41 |to a TEX T or IMA|
0080 47 45 20 74 79 70 65 2e-20 54 68 69 73 20 69 73 |GE type. This is|
0090 20 69 6c 6c 65 67 61 6c-20 69 6e 20 61 20 64 79 | illegal in a dy|
00a0 6e 61 6d 69 63 20 50 52-45 50 41 52 45 20 73 74 |namic PR EPARE st|
00b0 61 74 65 6d 65 6e 74 2e-0a 00 0a 67 70 77 77 32 |atement. ...gpww2|
00c0 33 36 30 30 30 01 00 fd-02 00 02 00 00 00 00 00 |36000... ........|

Sybase refuse to use placeholders with image !!

Test 2 - try to send parameters like store procedures

Creating prepared statement
Sending packet @ 2003-05-01 08:53:34.434845
0000 0f 01 00 63 00 00 00 00-e7 5c 00 01 00 0a 67 70 |...c.... .\....gp|
0010 77 77 32 33 36 30 30 30-49 00 63 72 65 61 74 65 |ww236000 I.create|
0020 20 70 72 6f 63 20 67 70-77 77 32 33 36 30 30 30 | proc gp ww236000|
0030 20 40 50 31 20 69 6d 61-67 65 20 61 73 20 69 6e | @P1 ima ge as in|
0040 73 65 72 74 20 69 6e 74-6f 20 23 62 69 6e 61 72 |sert int o #binar|
0050 79 5f 74 65 73 74 20 76-61 6c 75 65 73 20 28 40 |y_test v alues (@|
0060 50 31 29 |P1)|


Received header @ 2003-05-01 08:53:34.452216
0000 04 01 00 8b 00 00 00 00 |........|


Received packet @ 2003-05-01 08:53:34.452310
0000 e7 0d 00 20 00 0a 67 70-77 77 32 33 36 30 30 30 |... ..gp ww236000|
0010 e5 67 00 9a 00 00 00 09-0f 05 5a 5a 5a 5a 5a 00 |.g...... ..ZZZZZ.|
0020 01 00 48 00 50 61 72 61-6d 65 74 65 72 20 64 65 |..H.Para meter de|
0030 63 6c 61 72 61 74 69 6f-6e 20 6c 69 73 74 20 69 |claratio n list i|
0040 73 20 6e 6f 74 20 61 6c-6c 6f 77 65 64 20 69 6e |s not al lowed in|
0050 20 64 79 6e 61 6d 69 63-20 50 52 45 50 41 52 45 | dynamic PREPARE|
0060 20 73 74 61 74 65 6d 65-6e 74 2e 0a 00 0a 67 70 | stateme nt....gp|
0070 77 77 32 33 36 30 30 30-01 00 fd 02 00 02 00 00 |ww236000 ........|
0080 00 00 00 |...|

Sybase do not accept parameters declaration ...

Test 3 - trying using PARAMFMT

Creating prepared statement
2003-05-01 09:09:58.257913 tds_put_data_info putting status
2003-05-01 09:09:58.257963 HERE!
Sending packet @ 2003-05-01 09:09:58.257986
0000 0f 01 00 68 00 00 00 00-e7 4c 00 01 01 0a 67 70 |...h.... .L....gp|
0010 77 77 32 33 36 30 30 30-3d 00 63 72 65 61 74 65 |ww236000 =.create|
0020 20 70 72 6f 63 20 67 70-77 77 32 33 36 30 30 30 | proc gp ww236000|
0030 20 61 73 20 69 6e 73 65-72 74 20 69 6e 74 6f 20 | as inse rt into |
0040 23 62 69 6e 61 72 79 5f-74 65 73 74 20 76 61 6c |#binary_ test val|
0050 75 65 73 20 28 3f 29 ec-0e 00 01 00 00 00 00 00 |ues (?). ........|
0060 00 00 22 00 00 02 00 00 |..".....|


Received header @ 2003-05-01 09:09:58.268234
0000 04 01 01 98 00 00 00 00 |........|


Received packet @ 2003-05-01 09:09:58.268326
0000 e7 0d 00 20 00 0a 67 70-77 77 32 33 36 30 30 30 |... ..gp ww236000|
0010 e5 b4 00 de 0a 00 00 01-10 05 5a 5a 5a 5a 5a 00 |........ ..ZZZZZ.|
0020 01 00 95 00 41 6e 20 75-6e 74 79 70 65 64 20 76 |....An u ntyped v|
0030 61 72 69 61 62 6c 65 20-69 6e 20 74 68 65 20 50 |ariable in the P|
0040 52 45 50 41 52 45 20 73-74 61 74 65 6d 65 6e 74 |REPARE s tatement|
0050 20 27 67 70 77 77 32 33-36 30 30 30 27 20 69 73 | 'gpww23 6000' is|
0060 20 62 65 69 6e 67 20 72-65 73 6f 6c 76 65 64 20 | being r esolved |
0070 74 6f 20 61 20 54 45 58-54 20 6f 72 20 49 4d 41 |to a TEX T or IMA|
0080 47 45 20 74 79 70 65 2e-20 54 68 69 73 20 69 73 |GE type. This is|
0090 20 69 6c 6c 65 67 61 6c-20 69 6e 20 61 20 64 79 | illegal in a dy|
00a0 6e 61 6d 69 63 20 50 52-45 50 41 52 45 20 73 74 |namic PR EPARE st|
00b0 61 74 65 6d 65 6e 74 2e-0a 00 0a 67 70 77 77 32 |atement. ...gpww2|
00c0 33 36 30 30 30 01 00 fd-03 00 02 00 00 00 00 00 |36000... ........|
00d0 e5 b4 00 e4 0e 00 00 01-12 05 5a 5a 5a 5a 5a 00 |........ ..ZZZZZ.|
00e0 01 00 95 00 54 68 65 20-64 61 74 61 73 74 72 65 |....The datastre|
00f0 61 6d 20 66 6f 72 20 74-6f 6b 65 6e 20 32 33 36 |am for t oken 236|
0100 20 73 68 6f 75 6c 64 20-6f 6e 6c 79 20 62 65 20 | should only be |
0110 73 65 6e 74 20 61 66 74-65 72 20 6f 74 68 65 72 |sent aft er other|
0120 20 64 61 74 61 73 74 72-65 61 6d 73 2e 20 49 74 | datastr eams. It|
0130 20 63 61 6e 20 6e 6f 74-20 62 65 20 61 20 63 6f | can not be a co|
0140 6d 6d 61 6e 64 20 64 61-74 61 73 74 72 65 61 6d |mmand da tastream|
0150 20 6f 6e 20 69 74 27 73-20 6f 77 6e 2e 20 54 68 | on it's own. Th|
0160 69 73 20 69 73 20 61 6e-20 69 6e 74 65 72 6e 61 |is is an interna|
0170 6c 20 65 72 72 6f 72 2e-0a 00 0a 67 70 77 77 32 |l error. ...gpww2|
0180 33 36 30 30 30 01 00 fd-02 00 02 00 00 00 00 00 |36000... ........|

How to pass that types ??? Grrr....


>
> > Perhaps we can test tds->state after
> > tds_process_results_token but this lead future problem when
> > we implement full thread-safe...
>
> Is the question, When should we set "tds->state = TDS_IDLE"?
>

Is set (IMHO correctly) processing latest TDS_DONE* (there is a flags
that tell "this is the last")

freddy77





Archive powered by MHonArc 2.6.24.

Top of Page