Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Can't insert exactly 2000 chars into VARCHAR2(2000) column
Example code to produce the error:
/* * MySql.pc * * Example Pro*C Application for Windows V3.1 and Win32. * * by F. Lopez -- Desktop Products Division. * * Copyright 1991, Oracle Corporation. * * Modified - * kakiyama 05/05/97 - replaced sqlproto.h with sqlcpr.h and sqlda.h * rahmed 08/10/95 - Cleaned up build warnings, No need for WIN_NT macro. * syau 03/07/95 - WIN_NT: add prototype file * Hartenstine 04/17/93 - Port to Win32 * svander 11/23/92 - Removed ext. sqlald reference with updatedsqlproto.h
/* rahmed: adding WIN32_LEAN_AND_MEAN to have less number of
includes from windows.h
*/
#define WIN32_LEAN_AND_MEAN
#define ORACLE_NO_DATA_FOUND 1403
#define ORACLE_FETCH_VAL_NULL -1405
#define ORACLE_FETCH_OUT -1002
#define DEF_VARCHAR_LENGTH 2000
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <sqlda.h>
#include <sqlcpr.h>
#include <time.h>
#include <stdio.h>
#include "MySql.h"
#define COPYINTOVARCHAR( v, f, l ) v.len = min( l, DEF_VARCHAR_LENGTH );
memcpy(v.arr, f, v.len )
main()
{
... connect to ORACLE ....
InsertIntoScriptSave is called with a string 2000 bytes long:
char stringi[2000+1] = "....
IsertIntoScriptSave( 10, 10, stringi, 2000 );
... disconnect
exit(0);
}
BOOL InsertIntoScriptSave( int id, int seq, const char * n1, int n1len )
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR psscr[DEF_VARCHAR_LENGTH];
EXEC SQL END DECLARE SECTION;
int itmp1;
int itmp2;
itmp1 = id;
itmp2 = seq;
COPYINTOVARCHAR( psscr, n1, n1len );
EXEC SQL INSERT INTO tg_scripts ( tg_outputtg_id, scr_seq_nr, scr_main )
values ( :itmp1, :itmp2, :psscr );
if( !ProcessOracleErrorCode() )
return( FALSE );
return( TRUE );
}
/* The definition of the table tg_scripts is as follows: SQL> desc tg_scripts
Name Null? Type ------------------------------- -------- ---- TG_OUTPUTTG_ID NOT NULL NUMBER SCR_SEQ_NR NOT NULL NUMBER SCR_MAIN VARCHAR2(2000)*/ Received on Wed May 05 1999 - 12:13:49 CDT