21.02.2013 Views

System i: Programming i5/OS PASE - IBM

System i: Programming i5/OS PASE - IBM

System i: Programming i5/OS PASE - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Note: By using the code examples, you agree to the terms of the “Code license and disclaimer<br />

information” on page 70.<br />

/* <strong>i5</strong>/<strong>OS</strong> <strong>PASE</strong> DB2 for <strong>i5</strong>/<strong>OS</strong> example program<br />

*<br />

* To show an example of an <strong>i5</strong>/<strong>OS</strong> <strong>PASE</strong> program that accesses<br />

* <strong>i5</strong>/<strong>OS</strong> DB2 via SQL CLI<br />

*<br />

* Program accesses <strong>System</strong> i Access database, QIWS/QCUSTCDT, that<br />

* should exist on all systems<br />

*<br />

* Change system name, userid, and password in fun_Connect()<br />

* procedure to valid parms<br />

*<br />

* Compilation invocation:<br />

*<br />

* xlc -I./include -bI:./include/libdb400.exp -o paseclidb4 paseclidb4.c<br />

*<br />

* FTP in binary, run from QP2TERM() terminal shell<br />

*<br />

* Output should show all rows with a STATE column match of MN */<br />

/* Change Activity: */<br />

/* End Change Activity */<br />

#define SQL_MAX_UID_LENGTH 10<br />

#define SQL_MAX_PWD_LENGTH 10<br />

#define SQL_MAX_STM_LENGTH 255<br />

#include <br />

#include <br />

#include <br />

#include "sqlcli.h"<br />

SQLRETURN fun_Connect( void );<br />

SQLRETURN fun_DisConnect( void );<br />

SQLRETURN fun_ReleaseEnvHandle( void );<br />

SQLRETURN fun_ReleaseDbcHandle( void );<br />

SQLRETURN fun_ReleaseStmHandle( void );<br />

SQLRETURN fun_Process( void );<br />

SQLRETURN fun_Process2( void );<br />

void fun_PrintError( SQLHSTMT );<br />

SQLRETURN nml_ReturnCode;<br />

SQLHENV nml_HandleToEnvironment;<br />

SQLHDBC nml_HandleToDatabaseConnection;<br />

SQLHSTMT nml_HandleToSqlStatement;<br />

SQLINTEGER Nmi_vParam;<br />

SQLINTEGER Nmi_RecordNumberToFetch = 0;<br />

SQLCHAR chs_SqlStatement01[ SQL_MAX_STM_LENGTH +1];<br />

SQLINTEGER nmi_PcbValue;<br />

SQLINTEGER nmi_vParam;<br />

char *pStateName = "MN";<br />

void main( ) {<br />

static<br />

char*pszId = "main()";<br />

SQLRETURN nml_ConnectionStatus;<br />

SQLRETURN nml_ProcessStatus;<br />

nml_ConnectionStatus = fun_Connect();<br />

if ( nml_ConnectionStatus == SQL_SUCCESS ) {<br />

printf( "%s: fun_Connect() succeeded\n", pszId );<br />

} else {<br />

printf( "%s: fun_Connect() failed\n", pszId );<br />

exit( -1 );<br />

} /* endif */<br />

<strong>i5</strong>/<strong>OS</strong> <strong>PASE</strong> 43

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!