#include "stdafx.h"
#include <windows.h>

#define STRSAFE_NO_CB_FUNCTIONS
#define STRSAFE_NO_DEPRECATE

#include <strsafe.h>
#include <mysql.h>

int main(int argc, char* argv[]) {

    int erg;
    int Zaehl;
    char Buffer[64]={0};
    unsigned long BufferLen=0;
//  size_t Rest;

		HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD dwBytesWritten;

    const char *Queries[4]={
        "CREATE TABLE IF NOT EXISTS `tester01` ( \
        `ID` int(11) NOT NULL auto_increment, \
        `nummer` int(11) NOT NULL default 0, \
        `strnummer` varchar(64) NOT NULL default '', \
        PRIMARY KEY  (`id`) \
        );",
        "ALTER TABLE `tester01` DISABLE KEYS",
        "INSERT INTO `tester01` (`nummer`, `strnummer`) VALUES(?, ?)",
        "ALTER TABLE `tester01` ENABLE KEYS"
		};

    MYSQL *pMySQL=mysql_init((MYSQL*) 0);

    if (mysql_real_connect(pMySQL, "localhost", "root", "", "tester",
        3309, NULL, 0)) {

        /**********************************
				// Tabelle erstellen
				**********************************/
				erg=mysql_real_query(pMySQL, Queries[0], lstrlen(Queries[0]));
        if(erg!=0) {
            WriteConsole(hStdOut, mysql_error(pMySQL),
                lstrlen(mysql_error(pMySQL)), &dwBytesWritten, NULL);
				}

        /**********************************
				// Keys aus
				**********************************/
				erg=mysql_real_query(pMySQL, Queries[1], lstrlen(Queries[1]));
        if(erg!=0) {
            WriteConsole(hStdOut, mysql_error(pMySQL),
                lstrlen(mysql_error(pMySQL)), &dwBytesWritten, NULL);
				}

        MYSQL_STMT *pStmt=mysql_stmt_init(pMySQL);

        if(0==(erg=mysql_stmt_prepare(pStmt, Queries[2], lstrlen(Queries[2])))) {

            MYSQL_BIND MyBind[2]={0};

            MyBind[0].buffer_type=MYSQL_TYPE_LONG;
            MyBind[0].buffer=&Zaehl;
            MyBind[0].is_null=0;

/*          buffer_type    - One of the MYSQL_* types, used to describe
									the host language type of buffer.
									On output: if column type is different from
									buffer_type, column value is automatically converted
									to buffer_type before it is stored in the buffer.
*/
						MyBind[1].buffer_type=MYSQL_TYPE_VAR_STRING;
/*
						buffer         - On input: points to the buffer with input data.
									On output: points to the buffer capable to store
									output data.
									The type of memory pointed by buffer must correspond
									to buffer_type. See the correspondence table in
									the comment to mysql_stmt_bind_param.
*/
						MyBind[1].buffer=Buffer;
/*
						buffer_length  - the length of the buffer. You don't have to set
									it for any fixed length buffer: float, double,
									int, etc. It must be set however for variable-length
									types, such as BLOBs or STRINGs.
*/
//          MyBind[1].buffer_length=MAX_PATH;
/*
						length         - On input: in case when lengths of input values
									are different for each execute, you can set this to
									point at a variable containining value length. This
									way the value length can be different in each execute.
									If length is not NULL, buffer_length is not used.
									Note, length can even point at buffer_length if
									you keep bind structures around while fetching:
									this way you can change buffer_length before
									each execution, everything will work ok.
									On output: if length is set, mysql_stmt_fetch will
									write column length into it.
*/
						MyBind[1].length=&BufferLen;
/*
						is_null        - On input: points to a boolean variable that should
									be set to TRUE for NULL values.
									This member is useful only if your data may be
									NULL in some but not all cases.
									If your data is never NULL, is_null should be set to 0.
									If your data is always NULL, set buffer_type
									to MYSQL_TYPE_NULL, and is_null will not be used.
*/
						MyBind[1].is_null=0;

            if(0==(erg=mysql_stmt_bind_param(pStmt, MyBind))) {

                for(Zaehl=0; Zaehl<10000; Zaehl++) {

                    BufferLen=wsprintf(Buffer, "%d", Zaehl);

//                  StringCchPrintfEx(Buffer, 64, NULL, &Rest, 0, "%d", Zaehl);
//                  BufferLen=64-Rest;

										erg=mysql_stmt_execute(pStmt);
								}

						} else {
                WriteConsole(hStdOut, mysql_stmt_error(pStmt),
                    lstrlen(mysql_stmt_error(pStmt)), &dwBytesWritten, NULL);
						}

				} else {
            WriteConsole(hStdOut, mysql_stmt_error(pStmt),
                lstrlen(mysql_stmt_error(pStmt)), &dwBytesWritten, NULL);
				}

        erg=mysql_stmt_close(pStmt);

        /**********************************
				// Keys an
				**********************************/
				erg=mysql_real_query(pMySQL, Queries[3], lstrlen(Queries[3]));
        if(erg!=0) {
            WriteConsole(hStdOut, mysql_error(pMySQL),
                lstrlen(mysql_error(pMySQL)), &dwBytesWritten, NULL);
				}

		} else {
        WriteConsole(hStdOut, mysql_error(pMySQL),
            lstrlen(mysql_error(pMySQL)), &dwBytesWritten, NULL);
		}

    mysql_close(pMySQL);

    CloseHandle(hStdOut);

    return 0;
}
 
Coldfusion
->SerializeJSON

GCC
->Cross-Compiling

MySql
->Prep. Stmts

SQLite3
->Mem-Structure
->Prep. Stmts
->ToUTF8-Func
->ToWin1252-Func

UTF-8
->UTF-8 To UCS2

VB
->MD5-Class

VC++
->BZip2
->ATL


HOME

Google