I just follow the manual of ESQLC.pdf of ASE15.0.3 the sample of image/text
read/writing.
Found that if fails to write the image/text data into the database after
"cpre -y" option.

I think this is a fatal issue.

Here is the program, could anyone help verify it? Is there any fix/EBF?


#define ERREXIT -1
#define STDEXIT 0

#include <stdio.h>

/* Declare the SQLCA. */
EXEC SQL INCLUDE SQLCA;

#define EOLN '\0'

void error_handler(void)
{
fprintf(stderr, "\n** SQLCODE=(%ld)", sqlca.sqlcode);
if (sqlca.sqlerrm.sqlerrml)
{
fprintf(stderr, "\n** ASE Error ");
fprintf(stderr, "\n** %s", sqlca.sqlerrm.sqlerrmc);
}
fprintf(stderr, "\n\n");
exit(ERREXIT);
}

void warning_handler(void)
{

if (sqlca.sqlwarn[1] == 'W')
{
fprintf(stderr,
"\n** Data truncated.\n");
}

if (sqlca.sqlwarn[3] == 'W')
{
fprintf(stderr,
"\n** Insufficient host variables to store results.\n");
}
return;
}

int main()
{
int i = 0;
EXEC SQL BEGIN DECLARE SECTION;
/* storage for login name and password. */
char username[30];
char password[30];
char servername[30];
char dbname[30];
EXEC SQL END DECLARE SECTION;

EXEC SQL BEGIN DECLARE SECTION;
CS_INT id;
CS_IMAGE col2_var[50000];
CS_TEXT col3_var[50000];
CS_SMALLINT retcode;
CS_INT col2_len;
CS_INT col3_len;
EXEC SQL END DECLARE SECTION;

EXEC SQL WHENEVER SQLERROR CALL error_handler();
EXEC SQL WHENEVER SQLWARNING CALL warning_handler();
EXEC SQL WHENEVER NOT FOUND CONTINUE;

strcpy(username, "spring");
strcpy(password, "spring1");
strcpy(servername, "SEANLAPTOP");
strcpy(dbname, "iihero");
EXEC SQL CONNECT :username IDENTIFIED BY :password USING :servername;
EXEC SQL USE :dbname;

printf("Begin test!\n");

/* set max text size 1000KB */
EXEC SQL set textsize 1024000;

/* create a demo table first */
EXEC SQL create table foo(id int primary key, col2 image null, col3 text
null);
printf("table foo created. \n");

/* test insert and update data in table foo */
id = 1;
strcpy(col2_var, "abcd");
strcpy(col3_var, "����");
for (i = 4; i < 50000; i++)
{
col2_var[i] = 'f';
col3_var[i] = '@';
}
EXEC SQL insert into foo (id, col2, col3) values( :id, :col2_var,
:col3_var );
if ( sqlca.sqlcode == 0 )
{
printf("Row successfully inserted! \n");
EXEC SQL COMMIT WORK;
}
/* reset col2 and col3 */
strcpy(col2_var, "");
strcpy(col3_var, "");

/* fetch the image/text rows */
EXEC SQL DECLARE foo CURSOR FOR
SELECT id, col2, col3, datalength(col2), datalength(col3) FROM foo order
by id;

EXEC SQL OPEN foo;
printf("The rows of foo: \n");
for (;;)
{
EXEC SQL FETCH foo INTO :id, :col2_var, :col3_var, :col2_len,
:col3_len;
if (sqlca.sqlcode == 100)
break;
printf("id=%ld, col2 len=%ld, col3 len=%ld\n", id, col2_len,
col3_len);
}
EXEC SQL CLOSE foo;

/* drop the demo table: foo */
EXEC SQL drop table foo;
printf("table foo dropped. \n");

EXEC SQL DISCONNECT ALL;

printf("End test!\n");

return STDEXIT;
}