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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
//Burton
#include <windows.h>
#include <stdio.h>
#include <sqlext.h>
const char* DAM = "Direct ODBC";
SQLCHAR szDSN[256] =
"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=C:\\FILEBLOCK\\Fileblocker.accdb;";
main()
{
HENV hEnv, hEnv2, hEnv3, hEnv4, hEnv5;
HDBC hDbc, hDbc2, hDbc3, hDbc4, hDbc5;
SQLRETURN rc, NEW, TOTAL, QUOTA, UP;
SQLSMALLINT iConnStrLength2Ptr;
SQLCHAR szConnStrOut[255];
SQLCHAR* query = (SQLCHAR*)"SELECT tblIP.[IPAddress], tblIP.[IPType], tblIP.[IPStatus], tblIP.[IPMax] FROM tblIP WHERE tblIP.[IPAddress]='173.201.216.2' AND tblIP.[IPType]=3 AND tblIP.[IPStatus]=1 AND tblIP.[IPMax]=0;";
SQLCHAR* query2 = (SQLCHAR*)"INSERT INTO tblDownloads (tblDownloads.[DownloadIP] , tblDownloads.[DownloadCount]) VALUES('173.201.216.2', 1)";
SQLCHAR* query3 = (SQLCHAR*)"SELECT SUM(DownloadCount) AS DT FROM tblDownloads WHERE tblDownloads.[DownloadIP]='173.201.216.2'";
SQLCHAR* query4 = (SQLCHAR*)"SELECT tblIP.[IPQuota] FROM tblIP WHERE tblIP.[IPAddress] = '173.201.216.2'";
SQLCHAR* query5 = (SQLCHAR*)"UPDATE tblIP SET tblIP.[IPMax] WHERE tblIP.[IPAddress] = '173.201.216.2'";
/* Number of rows and columns in result set */
SQLINTEGER rowCount = 0;
SQLSMALLINT fieldCount = 0;
HSTMT hStmt, hStmt2, hStmt3, hStmt4, hStmt5;
/* Allocate an environment handle */
rc = SQLAllocEnv(&hEnv);
NEW = SQLAllocEnv(&hEnv2);
TOTAL = SQLAllocEnv(&hEnv3);
QUOTA = SQLAllocEnv(&hEnv4);
UP = SQLAllocEnv(&hEnv5);
/* Allocate a connection handle */
rc = SQLAllocConnect(hEnv, &hDbc);
NEW = SQLAllocConnect(hEnv3, &hDbc2);
TOTAL = SQLAllocConnect(hEnv3, &hDbc3);
QUOTA = SQLAllocConnect(hEnv4, &hDbc4);
UP = SQLAllocConnect(hEnv5, &hDbc5);
/* Connect to the 'Fileblocker.accdb' database */
rc = SQLDriverConnect(hDbc, NULL, szDSN, _countof(szDSN),
szConnStrOut, 255, &iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
if (SQL_SUCCEEDED(rc))
{
printf("%s: Successfully connected to database. Data source name: \n %s\n",
DAM, szConnStrOut);
/* Prepare SQL query */
rc = SQLAllocStmt(hDbc,&hStmt);
rc = SQLPrepare(hStmt, query, SQL_NTS);
/* Execute the query and create a record set */
rc = SQLExecute(hStmt);
/* Loop through the rows in the result set */
rc = SQLFetch(hStmt);
while (SQL_SUCCEEDED(rc))
{
rc = SQLFetch(hStmt);
rowCount++;
};
printf("%s: Total Legit IP Count: %d\n", DAM, rowCount);
rc = SQLFreeStmt(hStmt, SQL_DROP);
if (rowCount >= 1)
{
printf("PASS\n");
NEW = SQLDriverConnect(hDbc2, NULL, szDSN, _countof(szDSN), szConnStrOut, 255, &iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
NEW = SQLAllocStmt(hDbc2,&hStmt2);
NEW = SQLPrepare(hStmt2, query2, SQL_NTS);
NEW = SQLExecute(hStmt2);
NEW = SQLFreeStmt(hStmt2, SQL_DROP);
TOTAL = SQLDriverConnect(hDbc3, NULL, szDSN, _countof(szDSN), szConnStrOut, 255, &iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
TOTAL = SQLAllocStmt(hDbc3,&hStmt3);
TOTAL = SQLPrepare(hStmt3, query3, SQL_NTS);
TOTAL = SQLExecute(hStmt3);
TOTAL = SQLFetch(hStmt3);
printf("%s: Total of Downloads: %d\n", DAM, TOTAL);
TOTAL = SQLFreeStmt(hStmt3, SQL_DROP);
QUOTA = SQLDriverConnect(hDbc4, NULL, szDSN, _countof(szDSN), szConnStrOut, 255, &iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
QUOTA = SQLAllocStmt(hDbc4,&hStmt4);
QUOTA = SQLPrepare(hStmt4, query4, SQL_NTS);
QUOTA = SQLExecute(hStmt4);
QUOTA = SQLFetch(hStmt4);
printf("%s: Quota For IP Address: %d\n", DAM, QUOTA);
QUOTA = SQLFreeStmt(hStmt4, SQL_DROP);
if (TOTAL >= QUOTA)
{
UP = SQLDriverConnect(hDbc5, NULL, szDSN, _countof(szDSN), szConnStrOut, 255, &iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
UP = SQLAllocStmt(hDbc5,&hStmt5);
UP = SQLPrepare(hStmt5, query5, SQL_NTS);
UP = SQLExecute(hStmt5);
UP = SQLFetch(hStmt5);
UP = SQLFreeStmt(hStmt5, SQL_DROP);
}
else if (rowCount == 0)
{
printf("FAIL\n");
rc = SQLFreeStmt(hStmt, SQL_DROP);
}
system("pause");
//}
}
else
{
printf("%s: Couldn't connect to %s.\n", DAM, szDSN);
}
/* Disconnect and free up allocated handles */
SQLDisconnect(hDbc);
SQLDisconnect(hDbc2);
SQLDisconnect(hDbc3);
SQLDisconnect(hDbc4);
SQLDisconnect(hDbc5);
SQLFreeHandle(SQL_HANDLE_DBC, hDbc);
SQLFreeHandle(SQL_HANDLE_DBC, hDbc2);
SQLFreeHandle(SQL_HANDLE_DBC, hDbc3);
SQLFreeHandle(SQL_HANDLE_DBC, hDbc4);
SQLFreeHandle(SQL_HANDLE_DBC, hDbc5);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv2);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv3);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv4);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv5);
}
}
|