Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Sybase ASA, ASE, IQ [игнор отключен] [закрыт для гостей] / ASE 12.5, OCE / ESQL C - как IMAGE вынуть ? / 9 сообщений из 9, страница 1 из 1
11.01.2006, 01:04
    #33475330
ska
ska
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
ASE 12.5, OCE / ESQL C - как IMAGE вынуть ?
Ну братцы,

всего 4 дня с этой радостью имею счастье - задрал он меня своей простотой.
Как вообще с varchar или image можно работать то в ESQL ?
(нужно из Кобола но и для C++ как пример подойдет)

1. Похоже что элементарных вещей оно не хавает:

create table T(m IMAGE)

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
EXEC SQL BEGIN DECLARE SECTION;
struct {
        short rlen;
        unsigned char  data[ 10000 ];
} buf;
EXEC SQL END DECLARE SECTION;
...
EXEC SQL SELECT m INTO :buf FROM T;
...

SELECT errcode = -16843013, error: ct_bind(): user api layer: external error: An illegal value of 2 given
:-))

Ну ладно, допустим вынуть то с грехом пополам я выну
(select datalength(m), m into ...)

а как вставить/заменить ?????????????????????????

2. C++ дает банальные ошибки компилируя после препроцессора.
Приходится или руками cast вставлять или на обычный C сваливать :-(((


Вот уж правду говорят дрянная база...

--
Сергей
...
Рейтинг: 0 / 0
11.01.2006, 17:38
    #33477263
White Owl
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
ASE 12.5, OCE / ESQL C - как IMAGE вынуть ?
Плохому танцору яйца мешают, а плохому программисту - база.

Пример из документации:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
#define DATA_LEN  128000 
void get_test_var()
/*****************/
{
    LONGVARCHAR *longptr;
    SQLDA *sqlda;
    SQLVAR *sqlvar;

    sqlda = alloc_sqlda(  1  );
    longptr = (LONGVARCHAR *)malloc(
                 LONGVARCHARSIZE( DATA_LEN ) );
    if( sqlda == NULL || longptr == NULL ) {
        fatal_error( "Allocation failed" );
    }

    // init longptr for receiving data
    longptr->array_len = DATA_LEN;

    // init sqlda for receiving data
    // (sqllen is unused with DT_LONG types)
    sqlda->sqld =  1 ;   // using 1 sqlvar
    sqlvar = &sqlda->sqlvar[ 0 ];
    sqlvar->sqltype = DT_LONGVARCHAR;
    sqlvar->sqldata = longptr;

    printf( "fetching test_var\n" );
    EXEC SQL PREPARE select_stmt FROM 'SELECT test_var';
    EXEC SQL EXECUTE select_stmt INTO DESCRIPTOR sqlda;
    EXEC SQL DROP STATEMENT select_stmt;
    printf( "stored_len: %d, untrunc_len: %d,
       1st char: %c, last char: %c\n",
        longptr->stored_len,
        longptr->untrunc_len,
        longptr->array[ 0 ],
        longptr->array[DATA_LEN- 1 ] );
    free_sqlda( sqlda );
    free( longptr );
}
...
Рейтинг: 0 / 0
11.01.2006, 17:52
    #33477319
gardenman
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
ASE 12.5, OCE / ESQL C - как IMAGE вынуть ?
2 White Owl
Ну-ну... Врубил на всю катушку Dynamic SQL и назвал ska плохим танцором...
Нехорошо. Извиницца надо....

2 ska по существу:
Зря вы ESQL + ASE. Не стоит оно того. Один лишь геморрой.
С++ - сразу отбрасывайте.
уходите на ODBC+ХП, только так можно что-то приличное получить. (ИМХО)
...
Рейтинг: 0 / 0
11.01.2006, 19:13
    #33477481
Zhora
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
ASE 12.5, OCE / ESQL C - как IMAGE вынуть ?
Тут http://www.sybase.com/detail?id=20375 вроде есть text_image sample, не поможет - откройте case с Sybase.
...
Рейтинг: 0 / 0
11.01.2006, 19:23
    #33477497
ska
ska
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
ASE 12.5, OCE / ESQL C - как IMAGE вынуть ?
gardenman
2 ska по существу:
Зря вы ESQL + ASE. Не стоит оно того. Один лишь геморрой.
С++ - сразу отбрасывайте.
уходите на ODBC+ХП, только так можно что-то приличное получить. (ИМХО)

Ах Сударь, если бы речь шла о новой разработке...
Примерно 300 кобольных программ с ESQL :-((
Работают терпимо с Oracle, DB2 (rs6000, 390, as400) и даже MSSQL.
С++ немного - только для связки. ODBC в solaris ? Хммм.

Наверное перенести INSERT/UPDATE в ХП таки здравая идея.
По крайней мере хоть какой-то вариант сделать запись переменной длины в IMAGE или TEXT из кобола. Пока другого варианта не вижу.

Спасибо за совет
Сергей
...
Рейтинг: 0 / 0
12.01.2006, 00:50
    #33477746
ska
ska
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
ASE 12.5, OCE / ESQL C - как IMAGE вынуть ?
ZhoraТут http://www.sybase.com/detail?id=20375 вроде есть text_image sample, не поможет - откройте case с Sybase.

Угу, токмо фактическая длина поля не регулируется и получается равной размеру описанного буфера (как и положено в коболе добитого справа пробелами). Задать же фактическую длину не знаю как, если вообще возможно.
...
Рейтинг: 0 / 0
12.01.2006, 04:18
    #33477786
ska
ska
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
ASE 12.5, OCE / ESQL C - как IMAGE вынуть ?
White OwlПлохому танцору яйца мешают, а плохому программисту - база.

Пример из документации:
Код: plaintext
1.
2.
3.
4.
void get_test_var()
{
    LONGVARCHAR *longptr;
...


sybtestc.pc:16: error: `LONGVARCHAR' undeclared (first use in this function)

fgrep LONGVARCHAR $SYBASE/OCS-12_5/include/*
- нету

И хде енто Вы вычитали ?
:-))
...
Рейтинг: 0 / 0
12.01.2006, 18:13
    #33479842
White Owl
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
ASE 12.5, OCE / ESQL C - как IMAGE вынуть ?
Embedded SQL Programming
Sending and retrieving long valuesThe method for sending and retrieving LONG VARCHAR and LONG BINARY values in embedded SQL applications is different from that for other data types. Although the standard SQLDA fields can be used, they are limited to 32 kb data as the fields holding the information (sqldata, sqllen, sqlind) are 16-bit values. Changing these values to 32-bit values would break existing applications.

The method of describing LONG VARCHAR and LONG BINARY values is the same as for other data types.

For information about how to retrieve and send values, see Retrieving LONG data, and Sending LONG data.

Static SQL usage
Separate structures are used to hold the allocated, stored, and untruncated lengths of LONG BINARY and LONG VARCHAR data types. The static SQL data types are defined in sqlca.h as follows:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
#define DECL_LONGVARCHAR( size )         \
  struct { a_sql_uint32    array_len;    \
           a_sql_uint32    stored_len;   \
           a_sql_uint32    untrunc_len;  \
           char            array[size+ 1 ];\
         }
#define DECL_LONGBINARY( size )          \
  struct { a_sql_uint32    array_len;    \
           a_sql_uint32    stored_len;   \
           a_sql_uint32    untrunc_len;  \
           char            array[size];  \
         }
Dynamic SQL usage
For dynamic SQL, set the sqltype field to DT_LONGVARCHAR or DT_LONGBINARY as appropriate. The associated LONGBINARY and LONGVARCHAR structures are as follows:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
typedef struct LONGVARCHAR {
    a_sql_uint32    array_len;
           /* number of allocated bytes in array */
    a_sql_uint32    stored_len;
           /* number of bytes stored in array
            * (never larger than array_len)
            */
    a_sql_uint32    untrunc_len;
           /* number of bytes in untruncated expression
            * (may be larger than array_len)
            */
    char            array[ 1 ];   /* the data */
} LONGVARCHAR, LONGBINARY;
For information about how to implement this feature in your applications, see Retrieving LONG data, and Sending LONG data.

Embedded SQL Programming
Sending and retrieving long values
Retrieving LONG dataThis section describes how to retrieve LONG values from the database. For background information, see Sending and retrieving long values.

The procedures are different depending on whether you are using static or dynamic SQL.

To receive a LONG VARCHAR or LONG BINARY value (static SQL)
Declare a host variable of type DECL_LONGVARCHAR or DECL_LONGBINARY, as appropriate.

Retrieve the data using FETCH, GET DATA, or EXECUTE INTO. Adaptive Server Anywhere sets the following information:

indicator variable The indicator variable is negative if the value is NULL, 0 if there is no truncation, and is the positive untruncated length in bytes up to a maximum of 32767.

For more information, see Indicator variables.

stored_len This DECL_LONGVARCHAR or DECL_LONGBINARY field holds the number of bytes retrieved into the array. It is never greater than array_len.

untrunc_len This DECL_LONGVARCHAR or DECL_LONGBINARY field holds the number of bytes held by the database server. It is at least equal to the stored_len value. It is set even if the value is not truncated.

To receive a value into a LONGVARCHAR or LONGBINARY structure (dynamic SQL)
Set the sqltype field to DT_LONGVARCHAR or DT_LONGBINARY as appropriate.

Set the sqldata field to point to the LONGVARCHAR or LONGBINARY structure.

You can use the LONGVARCHARSIZE( n ) or LONGBINARYSIZE( n ) macros to determine the total number of bytes to allocate to hold n bytes of data in the array field.

Set the array_len field of the LONGVARCHAR or LONGBINARY structure to the number of bytes allocated for the array field.

Retrieve the data using FETCH, GET DATA, or EXECUTE INTO. Adaptive Server Anywhere sets the following information:

* sqlind This sqlda field is negative if the value is NULL, 0 if there is no truncation, and is the positive untruncated length in bytes up to a maximum of 32767.

stored_len This LONGVARCHAR or LONGBINARY field holds the number of bytes retrieved into the array. It is never greater than array_len.

untrunc_len This LONGVARCHAR or LONGBINARY field holds the number of bytes held by the database server. It is at least equal to the stored_len value. It is set even if the value is not truncated.

The following code snippet illustrates the mechanics of retrieving LONG VARCHAR data using dynamic embedded SQL. It is not intended to be a practical application:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
#define DATA_LEN  128000 
void get_test_var()
/*****************/
{
    LONGVARCHAR *longptr;
    SQLDA *sqlda;
    SQLVAR *sqlvar;

    sqlda = alloc_sqlda(  1  );
    longptr = (LONGVARCHAR *)malloc(
                 LONGVARCHARSIZE( DATA_LEN ) );
    if( sqlda == NULL || longptr == NULL ) {
        fatal_error( "Allocation failed" );
    }

    // init longptr for receiving data
    longptr->array_len = DATA_LEN;

    // init sqlda for receiving data
    // (sqllen is unused with DT_LONG types)
    sqlda->sqld =  1 ;   // using 1 sqlvar
    sqlvar = &sqlda->sqlvar[ 0 ];
    sqlvar->sqltype = DT_LONGVARCHAR;
    sqlvar->sqldata = longptr;

    printf( "fetching test_var\n" );
    EXEC SQL PREPARE select_stmt FROM 'SELECT test_var';
    EXEC SQL EXECUTE select_stmt INTO DESCRIPTOR sqlda;
    EXEC SQL DROP STATEMENT select_stmt;
    printf( "stored_len: %d, untrunc_len: %d,
       1st char: %c, last char: %c\n",
        longptr->stored_len,
        longptr->untrunc_len,
        longptr->array[ 0 ],
        longptr->array[DATA_LEN- 1 ] );
    free_sqlda( sqlda );
    free( longptr );
}
...
Рейтинг: 0 / 0
12.01.2006, 19:40
    #33479991
ska
ska
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
ASE 12.5, OCE / ESQL C - как IMAGE вынуть ?
White Owl Embedded SQL Programming
Sending and retrieving long values

Вы бы еще по Ораклу доки прислали.
Мы не говорим об ASA и о ODBC тоже
...
Рейтинг: 0 / 0
Форумы / Sybase ASA, ASE, IQ [игнор отключен] [закрыт для гостей] / ASE 12.5, OCE / ESQL C - как IMAGE вынуть ? / 9 сообщений из 9, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]