Example #1
0
void
test ()
{
  HSTMT hstmt;
  SQLRETURN rc;

  rc = SQLAllocHandle (SQL_HANDLE_STMT, (SQLHANDLE) hdbc,
      (SQLHANDLE *) & hstmt);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("SQLAllocHandle() failed.\n");
      return;
    }

  rc = SQLPrepare (hstmt, "burstoff_rs_proc ()", SQL_NTS);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("prepare failed.\n");
      error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
      exit (1);
    }

  call_proc (10);
  printf ("test: SQLExecute\n");

  rc = SQLExecute (hstmt);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("exec failed.\n");
      error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
      exit (1);
    }
  printf ("test: SQLFetch\n");
  rc = SQLFetch (hstmt);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("fetch failed.\n");
      error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
      exit (1);
    }
  printf ("test: SQLCancel\n");
  rc = SQLCancel (hstmt);
  if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
    {
      err_printf ("SQLCancel() failed.\n");
      exit (-1);
    }

  printf ("test: SQLFreeHandle\n");
  rc = SQLFreeHandle (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
}
extern "C" void ODBC_SIGTERM_handler(int signal)
{
	struct sigaction newActionHandler;

	CStmt *pStmt;
	std::list<CHandlePtr>::iterator i;
	CHandlePtr		pHandle;
	CHANDLECOLLECT handleCollection = 	gDrvrGlobal.gHandle.getHandles();

	for(i = handleCollection.begin(); i !=  handleCollection.end() ; ++i)
	{
		if ((pHandle = (CHandlePtr)(*i)) != NULL)		
		{
			if (pHandle->getHandleType() == SQL_HANDLE_STMT)
				SQLCancel((SQLHSTMT)pHandle);
		}

	} // for all handles

   sigaction(SIGTERM,&gOldSigTermActionHandler,NULL);
   raise(SIGTERM);
} // ODBC_SIGTERM_handler()
Example #3
0
File: 2punkt3.c Project: Nos-/htw
int getBerufe(SQLHENV *henv, SQLHDBC *hdbc, SQLHSTMT *hstmt, char *beruf) {
	// sql vars
	SQLCHAR kBeruf[BERUFSIZE + 1];
	SQLLEN bindLen;
	SQLRETURN rc;

	// input buffer
	char vBuf[VBUFSIZE];

	// SQL statement
	char *sqlStatement = "SELECT DISTINCT(Beruf) FROM Mitarbeiter";
	if (DEBUGINFO) printf("sqlStatement: \"%s\"\n", sqlStatement);

	// perform the SQL statement
	rc = SQLExecDirect(*hstmt, (SQLCHAR *)sqlStatement, SQL_NTS);
	if (!checkReturnCode("SQLExecDirect [hstmt, sqlStatement]", rc, *hstmt, SQL_HANDLE_STMT)) {
		freeSQLHandles(henv, hdbc, hstmt); exit(0);
	}

	// bind columns
	rc = SQLBindCol(*hstmt, 1, SQL_C_CHAR, kBeruf, BERUFSIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 1, kOrt]", rc, *hstmt, SQL_HANDLE_STMT);

	puts("");

	// fetch and print each row of data
	int i = 0;
	while ((rc = SQLFetch(*hstmt)) != SQL_NO_DATA) {
		// check error and warning
		if (rc == SQL_ERROR) {
			printf("SQLFetch [hstmt]: SQL_ERROR\n");
			break;
		}
		if (rc == SQL_SUCCESS_WITH_INFO) {
			printf("SQLFetch [hstmt]: SQL_SUCCESS_WITH_INFO\n");
		}

		// process data
		printf("  %-*s\n", BERUFSIZE, kBeruf);

		i++;
	}

	// cancel statement handle
	rc = SQLCancel(*hstmt);
	if (!checkReturnCode("SQLCancel [hstmt]", rc, *hstmt, SQL_HANDLE_STMT)) {
		freeSQLHandles(henv, hdbc, hstmt); exit(0);
	}

	if (i == 0) {
		printf("  Keine Berufe vorhanden.\n");
	}

	// get input
	printf("\n Beruf ? ");
	fgets(vBuf, VBUFSIZE, stdin);
	vBuf[strlen(vBuf) - 1] = 0;
	strncpy_s(beruf, BERUFSIZE, vBuf, VBUFSIZE);

	return strlen(beruf);
}
Example #4
0
File: 2punkt3.c Project: Nos-/htw
int getProjektDetails(SQLHENV *henv, SQLHDBC *hdbc, SQLHSTMT *hstmt, char *beruf, char *mitID) {
	// sql vars
	SQLINTEGER proNr;
	SQLCHAR proName[PRONAMESIZE + 1];
	SQLDOUBLE istAnt;
	SQLDOUBLE planAnt;
	SQLCHAR istAnt2[4];
	SQLCHAR planAnt2[4];
	SQLLEN bindLen;
	SQLRETURN rc = 0;

	// input buffer
	char vBuf[VBUFSIZE];

	// SQL statement
	char *part1 = "SELECT p.ProNr, p.ProName, z.Istanteil, z.Plananteil FROM Zuordnung z JOIN Projekt p ON p.ProNr = z.ProNr WHERE z.MitID ='";
	char *part2 = "'";
	int size = strlen(part1) + strlen(mitID) + strlen(part1) + 1;
	char *sqlStatement = malloc(sizeof(char)* size);
	sprintf_s(sqlStatement, sizeof(char) * size, "%s%s%s", part1, mitID, part2);
	if (DEBUGINFO) printf("sqlStatement: \"%s\"\n", sqlStatement);

	// perform the SQL statement
	rc = SQLExecDirect(*hstmt, (SQLCHAR *)sqlStatement, SQL_NTS);
	if (!checkReturnCode("SQLExecDirect [hstmt, sqlStatement2]", rc, *hstmt, SQL_HANDLE_STMT)) {
		freeSQLHandles(henv, hdbc, hstmt); exit(0);
	}

	// bind columns
	rc = SQLBindCol(*hstmt, 1, SQL_C_LONG, &proNr, 0, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 1, proNr]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 2, SQL_C_CHAR, proName, PRONAMESIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 2, proName]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 3, SQL_C_DOUBLE, &istAnt, 1024, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 3, &istAnt]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 4, SQL_C_DOUBLE, &planAnt, 1024, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 4, &planAnt]", rc, *hstmt, SQL_HANDLE_STMT);
	//rc = SQLBindCol(*hstmt, 3, SQL_C_FLOAT, &istAnt, 0, &bindLen);
	//checkReturnCode("SQLBindCol [hstmt, 3, &istAnt]", rc, *hstmt, SQL_HANDLE_STMT);
	//rc = SQLBindCol(*hstmt, 4, SQL_C_FLOAT, &planAnt, 0, &bindLen);
	//checkReturnCode("SQLBindCol [hstmt, 4, &planAnt]", rc, *hstmt, SQL_HANDLE_STMT);

	// fetch and print each row of data
	int i = 0;
	while ((rc = SQLFetch(*hstmt)) != SQL_NO_DATA) {
		// check error and warning
		if (rc == SQL_ERROR) {
			printf("SQLFetch [hstmt]: SQL_ERROR\n");
			break;
		}
		if (rc == SQL_SUCCESS_WITH_INFO) {
			//printf("SQLFetch [hstmt]: SQL_SUCCESS_WITH_INFO\n");
		}

		// process data
		printf("  %ld %-*s %.2f %.2f \n", proNr, PRONAMESIZE, proName, istAnt, planAnt);

		i++;
	}

	// cancel statement handle
	rc = SQLCancel(*hstmt);
	if (!checkReturnCode("SQLCancel [hstmt]", rc, *hstmt, SQL_HANDLE_STMT)) {
		freeSQLHandles(henv, hdbc, hstmt); exit(0);
	}

	if (i == 0) {
		printf("  '%s' hat keine Projekte.\n", mitID);
		printf("\n ? ");
		fgets(vBuf, sizeof(vBuf), stdin);
		printf("----------------------------------------------------------------------------\n");
		return 0;
	}

	// wait
	printf("\n ? ");
	fgets(vBuf, sizeof(vBuf), stdin);
	printf("----------------------------------------------------------------------------\n");

	return 1;
}
Example #5
0
File: 2punkt3.c Project: Nos-/htw
int getMitDetails(SQLHENV *henv, SQLHDBC *hdbc, SQLHSTMT *hstmt, char *beruf, char *mitID) {
	// sql vars
	SQLCHAR mitNName[VNAMESIZE + 1];
	SQLCHAR mitVName[NNAMESIZE + 1];
	SQLCHAR ort[ORTSIZE + 1];
	SQLCHAR gebDat[GEBDATSIZE + 1];
	SQLCHAR telNr[TELNRSIZE + 1];
	SQLLEN bindLen;
	SQLRETURN rc = 0;

	// input buffer
	char vBuf[VBUFSIZE];

	// SQL statement
	char *part1 = "SELECT Nachname, Vorname, Ort, Beruf, Gebdat, Telnr FROM Mitarbeiter WHERE Beruf = '";
	char *part2 = "' AND MitID='";
	char *part3 = "'";
	int size = strlen(part1) + strlen(beruf) + strlen(part2) + strlen(mitID) + strlen(part3) + 1;
	char *sqlStatement = malloc(sizeof(char)* size);
	sprintf_s(sqlStatement, sizeof(char) * size, "%s%s%s%s%s", part1, beruf, part2, mitID, part3);
	if (DEBUGINFO) printf("sqlStatement: \"%s\"\n", sqlStatement);

	// perform the SQL statement
	rc = SQLExecDirect(*hstmt, (SQLCHAR *)sqlStatement, SQL_NTS);
	if (!checkReturnCode("SQLExecDirect [hstmt, sqlStatement]", rc, *hstmt, SQL_HANDLE_STMT)) {
		freeSQLHandles(henv, hdbc, hstmt); exit(0);
	}

	// bind columns
	rc = SQLBindCol(*hstmt, 1, SQL_C_CHAR, mitNName, NNAMESIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 1, mitNName]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 2, SQL_C_CHAR, mitVName, VNAMESIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 2, mitVName]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 3, SQL_C_CHAR, ort, ORTSIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 3, ort]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 4, SQL_C_CHAR, beruf, BERUFSIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 4, beruf]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 5, SQL_C_CHAR, gebDat, GEBDATSIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 5, gebDat]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 6, SQL_C_CHAR, telNr, TELNRSIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 6, telNr]", rc, *hstmt, SQL_HANDLE_STMT);

	puts("");

	// fetch and print each row of data
	int i = 0;
	while ((rc = SQLFetch(*hstmt)) != SQL_NO_DATA) {
		// check error and warning
		if (rc == SQL_ERROR) {
			printf("SQLFetch [hstmt]: SQL_ERROR\n");
			break;
		}
		if (rc == SQL_SUCCESS_WITH_INFO) {
			printf("SQLFetch [hstmt]: SQL_SUCCESS_WITH_INFO\n");
		}

		// process data
		printf("  %-*s %-*s %-*s %-*s %-*s %-*s\n", NNAMESIZE, mitNName, VNAMESIZE, mitVName, ORTSIZE, ort, BERUFSIZE, beruf, GEBDATSIZE, gebDat, TELNRSIZE, telNr);

		i++;
	}

	// cancel statement handle
	rc = SQLCancel(*hstmt);
	if (!checkReturnCode("SQLCancel [hstmt]", rc, *hstmt, SQL_HANDLE_STMT)) {
		freeSQLHandles(henv, hdbc, hstmt); exit(0);
	}

	if (i == 0) {
		printf("  '%s' ist in dem Kontext keine gueltige Mitarbeiter-ID.\n", mitID);
		printf("\n ? ");
		fgets(vBuf, sizeof(vBuf), stdin);
		printf("----------------------------------------------------------------------------\n");
		return 0;
	}

	return 1;	
}
Example #6
0
File: 2punkt3.c Project: Nos-/htw
int getMitarbeiter(SQLHENV *henv, SQLHDBC *hdbc, SQLHSTMT *hstmt, char *beruf, char *mitID) {
	// sql vars
	SQLCHAR mitVName[VNAMESIZE + 1];
	SQLCHAR mitNName[NNAMESIZE + 1];
	SQLLEN bindLen;
	SQLRETURN rc = 0;

	// input buffer
	char vBuf[VBUFSIZE];

	// SQL statement
	char *part1 = "SELECT MitID, Nachname, Vorname FROM Mitarbeiter WHERE Beruf = '";
	char *part2 = "'";
	int size = strlen(part1) + strlen(beruf) + strlen(part2) + 1;
	char *sqlStatement = malloc(sizeof(char)* size);
	sprintf_s(sqlStatement, sizeof(char) * size, "%s%s%s", part1, beruf, part2);
	if (DEBUGINFO) printf("sqlStatement: \"%s\"\n", sqlStatement);

	// perform the SQL statement
	rc = SQLExecDirect(*hstmt, (SQLCHAR *)sqlStatement, SQL_NTS);
	if (!checkReturnCode("SQLExecDirect [hstmt, sqlStatement]", rc, *hstmt, SQL_HANDLE_STMT)) {
		freeSQLHandles(henv, hdbc, hstmt); exit(0);
	}

	// bind columns
	rc = SQLBindCol(*hstmt, 1, SQL_C_CHAR, mitID, MITIDSIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 1, mitID]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 2, SQL_C_CHAR, mitNName, NNAMESIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 2, mitNName]", rc, *hstmt, SQL_HANDLE_STMT);
	rc = SQLBindCol(*hstmt, 3, SQL_C_CHAR, mitVName, VNAMESIZE + 1, &bindLen);
	checkReturnCode("SQLBindCol [hstmt, 3, mitVName]", rc, *hstmt, SQL_HANDLE_STMT);

	puts("");

	// fetch and print each row of data
	int i = 0;
	while ((rc = SQLFetch(*hstmt)) != SQL_NO_DATA) {
		// check error and warning
		if (rc == SQL_ERROR) {
			printf("SQLFetch [hstmt]: SQL_ERROR\n");
			break;
		}
		if (rc == SQL_SUCCESS_WITH_INFO) {
			printf("SQLFetch [hstmt]: SQL_SUCCESS_WITH_INFO\n");
		}

		// process data
		printf("  %-*s %-*s %-*s\n", MITIDSIZE, mitID, NNAMESIZE, mitNName, VNAMESIZE, mitVName);

		i++;
	}

	// cancel statement handle
	rc = SQLCancel(*hstmt);
	if (!checkReturnCode("SQLCancel [hstmt]", rc, *hstmt, SQL_HANDLE_STMT)) {
		freeSQLHandles(henv, hdbc, hstmt); exit(0);
	}

	if (i == 0) {
		printf("  Beruf '%s' ist nicht vorhanden.\n", beruf);
		printf("\n ? ");
		fgets(vBuf, sizeof(vBuf), stdin);
		printf("----------------------------------------------------------------------------\n");
		return 0;
	}

	// wait
	printf("\n Mitarbeiter-ID ? ");
	fgets(vBuf, VBUFSIZE, stdin);
	vBuf[strlen(vBuf) - 1] = 0;
	//strncpy_s(mitID, MITIDSIZE + 1 , vBuf, VBUFSIZE);
	strncpy_s(mitID, MITIDSIZE + 1, vBuf, MITIDSIZE);

	return 1;
}
Example #7
0
void sqlDisconnect(SQLHENV *henv, SQLHDBC *hdbc, SQLHSTMT *hstmt) {
  SQLRETURN rc = SQLCancel(*hstmt);
  checkReturnCode("SQLCancel [hstmt]", rc, hstmt, SQL_HANDLE_STMT);
  freeSQLHandles(henv, hdbc, SQL_NULL_HSTMT);
}
Example #8
0
SQLRETURN SendLongData(void)
{
	// Declare The Local Memory Variables

	SQLPOINTER Value;
	SQLCHAR Buffer[20];
	SQLCHAR InputParam[] = "Special Instructions";
	size_t DataSize = 0;
	unsigned char in_data[200];
	int i;
	for (i = 0; i < BUFSIZE; i++)
		in_data[i] = (unsigned char)(BUFSIZE - 1 - i);
	// Start The Data-At-Execution Sequence By Calling 
	// SQLParamData()
	rc = SQLParamData(StmtHandle, (SQLPOINTER *) & Value);
	VERBOSE("returned a value of  %s\n", (const char *)Value);
	// Examine The Contents Of Value (Returned By SQLParamData())
	// To Determine Which Data-At-Execution Parameter Currently
	// Needs Data
	if (strcmp((const char *)Value, (const char *)InputParam) == 0
	    && rc == SQL_NEED_DATA) {
		// As Long As Data Is Available For The Parameter, Retrieve
		// Part Of It From The External Data File And Send It To The
		// Data Source
		// while (InFile.get(Buffer, sizeof(Buffer)))
		//{
		while (DataSize < BUFSIZE) {
			for (i = DataSize; i < DataSize + CHUNKSIZE; i++) {
				Buffer[i - DataSize] = in_data[i];
				VERBOSE("Buffer[%d]=in_data[%d]=%d\n",
					i - DataSize, i, in_data[i]);
			}

			rc = SQLPutData(StmtHandle, (SQLPOINTER) Buffer,
					CHUNKSIZE);
			assert(rc == SQL_SUCCESS
			       || rc == SQL_SUCCESS_WITH_INFO);
			DataSize = DataSize + CHUNKSIZE;

			// If The Amount Of Data Retrieved Exceeds The Size Of 
			// The Column (Which Is 200 Bytes), Call The SQLCancel() 
			// Function To Terminate The Data-At-Execution 
			// Sequence And Exit
			if (DataSize > BUFSIZE) {
				rc = SQLCancel(StmtHandle);
				return (SQL_ERROR);
			}
		}

		// Call SQLParamData() Again To Terminate The 
		// Data-At-Execution Sequence
		rc = SQLParamData(StmtHandle, (SQLPOINTER *) & Value);

		// Display A Message Telling How Many Bytes Of Data Were Sent
		if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
			VERBOSE("Successfully inserted %d\n", DataSize);
			VERBOSE(" bytes of data into the database.\n");
		}

	}
	// Close The External Data File
	//InFile.close();

	// Return The ODBC API Return Code To The Calling Function 
	return (rc);
}