27.7.10.26 mysql_stmt_send_long_data()

my_bool mysql_stmt_send_long_data(MYSQL_STMT *stmt, unsigned int parameter_number, const char *data, unsigned long length)

Description

使应用程序能够将参数数据分段(或“块”)发送到服务器。在mysql_stmt_bind_param()之后和mysql_stmt_execute()之前调用此函数。可以多次调用它以发送字符或二进制数据值的一部分,该值必须是TEXTBLOB数据类型之一。

parameter_number指示与数据关联的参数。参数从 0 开始编号。data是指向包含要发送数据的缓冲区的指针,lengthtable 示缓冲区中的字节数。

Note

下一个mysql_stmt_execute()调用将忽略自上一个mysql_stmt_execute()mysql_stmt_reset()以来与mysql_stmt_send_long_data()一起使用的所有参数的绑定缓冲区。

如果您想重置/忘记发送的数据,可以使用mysql_stmt_reset()完成。参见第 27.7.10.22 节,“ mysql_stmt_reset()”

max_allowed_packet系统变量控制可以通过mysql_stmt_send_long_data()发送的参数值的最大大小。

Return Values

零成功。如果发生错误,则为非零值。

Errors

该参数没有字符串或二进制类型。

无效的参数号。

命令执行 Sequences 不正确。

MySQL 服务器已经消失了。

记不清。

出现未知错误。

Example

下面的示例演示如何以块的形式发送TEXT列的数据。它将数据值'MySQL - The most popular Open Source database'插入text_column列。 mysql变量被假定为有效的连接处理程序。

#define INSERT_QUERY "INSERT INTO \
                      test_long_data(text_column) VALUES(?)"

MYSQL_BIND bind[1];
long       length;

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].length= &length;
 bind[0].is_null= 0;

/* Bind the buffers */
if (mysql_stmt_bind_param(stmt, bind))
{
  fprintf(stderr, "\n param bind failed");
  fprintf(stderr, "\n %s", mysql_stmt_error(stmt));
  exit(0);
}

 /* Supply data in chunks to server */
 if (mysql_stmt_send_long_data(stmt,0,"MySQL",5))
{
  fprintf(stderr, "\n send_long_data failed");
  fprintf(stderr, "\n %s", mysql_stmt_error(stmt));
  exit(0);
}

 /* Supply the next piece of data */
 if (mysql_stmt_send_long_data(stmt,0,
           " - The most popular Open Source database",40))
{
  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);
}