In the DBMS centerline to create a database test,table bintest,data field data type can be tested with Longblob
Test file C:\\test.iso, you can find any one file to modify it, I am looking for an EXE program, modified for Test.iso just
Maximum test added file size is 650M (a true ISO file)
Note: Also to modify the Max_allowed_packet field in the My.ini file, I set the
Copy Code code as follows:
Max_allowed_packet = 1024M
#define HOST "localhost"//mysql server
#define USERNAME "Root"
#define PASSWORD "674800"
#define DATABASE "Test"
int port = 3306;
Mysql3.cpp:Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Winsock2.h>
#include <mysql.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#pragma comment (lib, "Libmysql.lib")
#define Insert_query "INSERT into Bintest (ID, data) VALUES (NULL,?)"
#define HOST "localhost"//mysql server
#define USERNAME "Root"
#define PASSWORD "674800"
#define DATABASE "Test"
int port = 3306;
int Get_file_size (char *path, off_t *size)
{
struct stat file_stats;
if (stat (path, &file_stats))
return-1;
*size = file_stats.st_size;
return 0;
}
void Test ()
{
Mysql_bind Bind[1];
unsigned long length;
char* pos = NULL;
off_t size;
file* FP;
char* filename = "C:\\test.iso";
if ((get_file_size (filename, &size) = = = 1)//Get the size of the file
{
Perror ("Get File Size");
Exit (1);
}
if (pos = (char *) malloc (sizeof (char) * (size+1)) = = NULL)
{
Perror ("malloc buf");
Exit (1);
}
if (fp = fopen (filename, "rb") = = NULL)//Read file
{
Perror ("fopen file");
Exit (1);
}
if (Fread (POS, 1, size, FP) < 0)//Read file failed
{
Perror ("Fread file");
Exit (1);
}
MYSQL *mysql = Mysql_init (NULL); MySQL Initialization
if (!mysql)
Return
if (!mysql_real_connect (Mysql,host,username,password, "test", port,null,0))//linked server
{
int ret = Mysql_errno (MySQL);
Mysql_close (MySQL);
Return
}
mysql_stmt *stmt = mysql_stmt_init (mysql);
if (!stmt)
{
fprintf (stderr, "Mysql_stmt_init (), Out of memory\n");
Exit (0);
}
if (Mysql_stmt_prepare (stmt, Insert_query, strlen (insert_query))
{
fprintf (stderr, "\ n mysql_stmt_prepare (), INSERT failed");
fprintf (stderr, "\ n%s", Mysql_stmt_error (stmt));
Exit (0);
}
memset (bind, 0, sizeof (BIND));
Bind[0].buffer_type= mysql_type_string;
Bind[0].buffer_type = Mysql_type_long;
Bind[0].buffer = pos;
Bind[0].buffer_type = Mysql_type_tiny;
Bind[0].buffer_type = Mysql_type_blob;
Bind[0].length= &length;
Bind[0].is_null= 0;
/* Bind the buffers * *
if (Mysql_stmt_bind_param (stmt, bind))
{
fprintf (stderr, "\ param bind failed");
fprintf (stderr, "\ n%s", Mysql_stmt_error (stmt));
Exit (0);
}
int rc = 0;
/* Supply data in chunks to server * *
if (Mysql_stmt_send_long_data (stmt,0, POS, size))
{
fprintf (stderr, "\ n send_long_data failed");
fprintf (stderr, "\ n%s", Mysql_stmt_error (stmt));
Exit (0);
}
pos + = size;
/* Supply The next piece of data * *
if (Mysql_stmt_send_long_data (stmt,0, POS, size))
{
fprintf (stderr, "\ n send_long_data failed");
fprintf (stderr, "\ n%s", Mysql_stmt_error (stmt));
Exit (0);
}
* Now, execute the query * *
if (Mysql_stmt_execute (stmt))
{
fprintf (stderr, "\ n Mysql_stmt_execute failed");
fprintf (stderr, "\ n%s", Mysql_stmt_error (stmt));
Exit (0);
}
}
int main ()
{
Test ();
Sleep (1);
return 0;
}
Run Result: