Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8653187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:28:59+00:00 2026-06-12T14:28:59+00:00

is there any smart way to write a byte array into varbinary or (other

  • 0

is there any smart way to write a byte array into varbinary or (other explain me)
im looking to make funciton like that

 bool writeBinary(char * someQuery, LPBYTE buffer)
 {
 }

when i using next function the data that happend in mysql not same to the buffer

void CDBManager::SetBinary(const char * lpszStatement, LPBYTE lpBinaryBuffer,  
ULONG    BinaryBufferSize)
{
MYSQL_STMT  *stmt;
MYSQL_BIND  bind[1];
char * shhh = new char[BinaryBufferSize];
// ----
memcpy(shhh, lpBinaryBuffer, BinaryBufferSize);

stmt = mysql_stmt_init(&getDB()->m_hMySQL);
printf("\n");
if(BinaryBufferSize >= 2752)
{
    for(int i = 0; i < BinaryBufferSize; i++)
    {
        if(lpBinaryBuffer[i] == 0xFF &&
                 lpBinaryBuffer[i+1] == 0xFF && lpBinaryBuffer[i+2] == 0xFF && lpBinaryBuffer[i+3] == 0xFF && lpBinaryBuffer[i+4] == 0xFF && lpBinaryBuffer[i+5] == 0xFF &&
                  lpBinaryBuffer[i+6] == 0xFF && lpBinaryBuffer[i+7] == 0xFF && lpBinaryBuffer[i+8] == 0xFF && lpBinaryBuffer[i+9] == 0xFF && lpBinaryBuffer[i+10] == 0xFF &&
                   lpBinaryBuffer[i+11] == 0xFF && lpBinaryBuffer[i+12] == 0xFF && lpBinaryBuffer[i+13] == 0xFF && lpBinaryBuffer[i+14] == 0xFF && lpBinaryBuffer[i+15] == 0xFF)
        {
        }
        else
        {
            printf("[%d] %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", i, lpBinaryBuffer[i],
                 lpBinaryBuffer[i+1],  lpBinaryBuffer[i+2],  lpBinaryBuffer[i+3],  lpBinaryBuffer[i+4],  lpBinaryBuffer[i+5],
                  lpBinaryBuffer[i+6],  lpBinaryBuffer[i+7],  lpBinaryBuffer[i+8],  lpBinaryBuffer[i+9],  lpBinaryBuffer[i+10],
                   lpBinaryBuffer[i+11],  lpBinaryBuffer[i+12],  lpBinaryBuffer[i+13],  lpBinaryBuffer[i+14],  lpBinaryBuffer[i+15]);
        }
        i+=15;
    }
}
printf("\n");

if(stmt == NULL)
{
    fprintf(stderr, " mysql_stmt_init(), out of memory\n");
}
else if(mysql_stmt_prepare(stmt, lpszStatement, strlen(lpszStatement)))
{
    fprintf(stderr, " mysql_stmt_prepare(), INSERT failed\n");
    fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
}
else
{
    memset(bind, 0, sizeof(bind));
    // ----
    bind[0].buffer_type     = MYSQL_TYPE_BLOB;
    bind[0].buffer          = (char *)shhh;
    bind[0].buffer_length   = BinaryBufferSize;
    bind[0].is_null         = 0;
    bind[0].length          = 0;
    // ----
    // allways filed? what? this calls they are good, i made by example on mysql.com so what dont work
    // it always return len 0 => no data saved in db
    if(mysql_stmt_bind_param(stmt, bind))
    {
        fprintf(stderr, " mysql_stmt_bind_param() failed\n");
        fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
    }
    else if(mysql_stmt_execute(stmt))
    {
        fprintf(stderr, " mysql_stmt_execute(), 1 failed\n");
        fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
    }
}
// ----
delete shhh;

}

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:29:01+00:00Added an answer on June 12, 2026 at 2:29 pm

    Between your bind and your execute, add the following line to upload the blob data to the server side:

    *mysql_stmt_send_long_data({stmt}, {field-number}, {data}, {data length});*

    if(mysql_stmt_send_long_data(stmt, 2, (const char*)ser.data(), data_length)) {
      ERROR("dehydrate : failed to send long data : %s", mysql_stmt_error(stmt));
      goto abort;
    }
    

    The field-number is zero-based, and would be 0 in your case since you only have the 1 field.

    Also, the blob type only supports up to 64k, you may want the “long blob” data type which is up to 1GB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any smart way to write a list comprehension over more than one
Is there any way to write a select record starting with a particular record?
Is there any way using log4net to automatically write date/time and class name/function name
Is there any smart way to avoid the verbosity of testing the nullity on
Is there any way to start foobar.js WSH-script in order that standard Task Manager
Is there any way to control and manual specification for start of teaser ?.
Is there any way to set the directory where you want to start a
Are there any third-party Templating Engines for Asp.net like we have smarty,savant for php
I would like to start making code patches to Rails. Are there any good
Is there any way in Notepad++ (or even with another tool) to change the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.