Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Problem to store file of size > 64 KB using BLOB in Interbase database

Problem to store file of size > 64 KB using BLOB in Interbase database

Scheduled Pinned Locked Moved Database
databasehelpc++csswpf
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    navneet professional
    wrote on last edited by
    #1

    Hi, I am successfully stored & retrieved image files of size less than 64 KB.But when I am storing a image file of size 3 MB, then there is no error,but it only stores partial data in database. Please refer the code: ------------------------------------------------------------------ 1. File CMyDb.hpp-----> class CMyDb : public CDatabase { public: CMyDb(); virtual ~CMyDb(); virtual void BindParameters( HSTMT hstmt ); BYTE* m_pabImage; // address of the data of the blob int m_nImageLen; // sizeof the data in the image, in bytes CString m_sStmt; // looks like "UPDATE MyTable SET myFld=? WHERE idxFld=123" }; ------------------------------------------------------------------ 2. File CMyDb.cpp-----> CMyDb::CMyDb() { m_pabImage = NULL; m_nImageLen = 0; } CMyDb::~CMyDb() { } void CMyDb::BindParameters( HSTMT hstmt) { SQLINTEGER nLenOrInd= m_nImageLen; SQLRETURN rc; if ( m_sStmt.Find("?") == -1 ) { // no binding needed return; } rc= SQLBindParameter( hstmt, (SQLSMALLINT)1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARCHAR, m_nImageLen, 0, (void*)m_pabImage, m_nImageLen, &nLenOrInd); } ------------------------------------------------------------------ 3. File Main.cpp-> CFile file (sFileName, CFile::modeRead);//|CFile::typeBinary); CFileStatus fileStatus; file.GetStatus(fileStatus); int nCntImgBytes= 3 * 1024 * 1024;//3MB buffer BYTE* pabData = (BYTE*)calloc(nCntImgBytes,sizeof(BYTE)); DWORD lTemp = file.ReadHuge((void*)pabData,fileStatus.m_size); pApp->pServerDatabase->m_pabImage = pabData; pApp->pServerDatabase->m_nImageLen = fileStatus.m_size; pApp->pServerDatabase->m_sStmt= "INSERT INTO TEST1 (\"NAME\" , \"myBlobfield\") VALUES ('2',?)"; pApp->pServerDatabase->ExecuteSQL( pApp->pServerDatabase->m_sStmt ); ------------------------------------------------------------------ Please reply me as soon as possible. Regards Navneet

    B S L 3 Replies Last reply
    0
    • N navneet professional

      Hi, I am successfully stored & retrieved image files of size less than 64 KB.But when I am storing a image file of size 3 MB, then there is no error,but it only stores partial data in database. Please refer the code: ------------------------------------------------------------------ 1. File CMyDb.hpp-----> class CMyDb : public CDatabase { public: CMyDb(); virtual ~CMyDb(); virtual void BindParameters( HSTMT hstmt ); BYTE* m_pabImage; // address of the data of the blob int m_nImageLen; // sizeof the data in the image, in bytes CString m_sStmt; // looks like "UPDATE MyTable SET myFld=? WHERE idxFld=123" }; ------------------------------------------------------------------ 2. File CMyDb.cpp-----> CMyDb::CMyDb() { m_pabImage = NULL; m_nImageLen = 0; } CMyDb::~CMyDb() { } void CMyDb::BindParameters( HSTMT hstmt) { SQLINTEGER nLenOrInd= m_nImageLen; SQLRETURN rc; if ( m_sStmt.Find("?") == -1 ) { // no binding needed return; } rc= SQLBindParameter( hstmt, (SQLSMALLINT)1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARCHAR, m_nImageLen, 0, (void*)m_pabImage, m_nImageLen, &nLenOrInd); } ------------------------------------------------------------------ 3. File Main.cpp-> CFile file (sFileName, CFile::modeRead);//|CFile::typeBinary); CFileStatus fileStatus; file.GetStatus(fileStatus); int nCntImgBytes= 3 * 1024 * 1024;//3MB buffer BYTE* pabData = (BYTE*)calloc(nCntImgBytes,sizeof(BYTE)); DWORD lTemp = file.ReadHuge((void*)pabData,fileStatus.m_size); pApp->pServerDatabase->m_pabImage = pabData; pApp->pServerDatabase->m_nImageLen = fileStatus.m_size; pApp->pServerDatabase->m_sStmt= "INSERT INTO TEST1 (\"NAME\" , \"myBlobfield\") VALUES ('2',?)"; pApp->pServerDatabase->ExecuteSQL( pApp->pServerDatabase->m_sStmt ); ------------------------------------------------------------------ Please reply me as soon as possible. Regards Navneet

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      There could be a size limit of the BLOB data type in the database engine you use here. I do not think that all database engines throw an exception when the data is more than the specified field can store, it seems your database just trims it down. I guess a better solution is to store the file somewhere on the file system, and to store the filename (including path) only in the database.

      1 Reply Last reply
      0
      • N navneet professional

        Hi, I am successfully stored & retrieved image files of size less than 64 KB.But when I am storing a image file of size 3 MB, then there is no error,but it only stores partial data in database. Please refer the code: ------------------------------------------------------------------ 1. File CMyDb.hpp-----> class CMyDb : public CDatabase { public: CMyDb(); virtual ~CMyDb(); virtual void BindParameters( HSTMT hstmt ); BYTE* m_pabImage; // address of the data of the blob int m_nImageLen; // sizeof the data in the image, in bytes CString m_sStmt; // looks like "UPDATE MyTable SET myFld=? WHERE idxFld=123" }; ------------------------------------------------------------------ 2. File CMyDb.cpp-----> CMyDb::CMyDb() { m_pabImage = NULL; m_nImageLen = 0; } CMyDb::~CMyDb() { } void CMyDb::BindParameters( HSTMT hstmt) { SQLINTEGER nLenOrInd= m_nImageLen; SQLRETURN rc; if ( m_sStmt.Find("?") == -1 ) { // no binding needed return; } rc= SQLBindParameter( hstmt, (SQLSMALLINT)1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARCHAR, m_nImageLen, 0, (void*)m_pabImage, m_nImageLen, &nLenOrInd); } ------------------------------------------------------------------ 3. File Main.cpp-> CFile file (sFileName, CFile::modeRead);//|CFile::typeBinary); CFileStatus fileStatus; file.GetStatus(fileStatus); int nCntImgBytes= 3 * 1024 * 1024;//3MB buffer BYTE* pabData = (BYTE*)calloc(nCntImgBytes,sizeof(BYTE)); DWORD lTemp = file.ReadHuge((void*)pabData,fileStatus.m_size); pApp->pServerDatabase->m_pabImage = pabData; pApp->pServerDatabase->m_nImageLen = fileStatus.m_size; pApp->pServerDatabase->m_sStmt= "INSERT INTO TEST1 (\"NAME\" , \"myBlobfield\") VALUES ('2',?)"; pApp->pServerDatabase->ExecuteSQL( pApp->pServerDatabase->m_sStmt ); ------------------------------------------------------------------ Please reply me as soon as possible. Regards Navneet

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        what database are you using?

        Marc Clifton wrote:

        That has nothing to do with VB. - Oh crap. I just defended VB!

        N 1 Reply Last reply
        0
        • N navneet professional

          Hi, I am successfully stored & retrieved image files of size less than 64 KB.But when I am storing a image file of size 3 MB, then there is no error,but it only stores partial data in database. Please refer the code: ------------------------------------------------------------------ 1. File CMyDb.hpp-----> class CMyDb : public CDatabase { public: CMyDb(); virtual ~CMyDb(); virtual void BindParameters( HSTMT hstmt ); BYTE* m_pabImage; // address of the data of the blob int m_nImageLen; // sizeof the data in the image, in bytes CString m_sStmt; // looks like "UPDATE MyTable SET myFld=? WHERE idxFld=123" }; ------------------------------------------------------------------ 2. File CMyDb.cpp-----> CMyDb::CMyDb() { m_pabImage = NULL; m_nImageLen = 0; } CMyDb::~CMyDb() { } void CMyDb::BindParameters( HSTMT hstmt) { SQLINTEGER nLenOrInd= m_nImageLen; SQLRETURN rc; if ( m_sStmt.Find("?") == -1 ) { // no binding needed return; } rc= SQLBindParameter( hstmt, (SQLSMALLINT)1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARCHAR, m_nImageLen, 0, (void*)m_pabImage, m_nImageLen, &nLenOrInd); } ------------------------------------------------------------------ 3. File Main.cpp-> CFile file (sFileName, CFile::modeRead);//|CFile::typeBinary); CFileStatus fileStatus; file.GetStatus(fileStatus); int nCntImgBytes= 3 * 1024 * 1024;//3MB buffer BYTE* pabData = (BYTE*)calloc(nCntImgBytes,sizeof(BYTE)); DWORD lTemp = file.ReadHuge((void*)pabData,fileStatus.m_size); pApp->pServerDatabase->m_pabImage = pabData; pApp->pServerDatabase->m_nImageLen = fileStatus.m_size; pApp->pServerDatabase->m_sStmt= "INSERT INTO TEST1 (\"NAME\" , \"myBlobfield\") VALUES ('2',?)"; pApp->pServerDatabase->ExecuteSQL( pApp->pServerDatabase->m_sStmt ); ------------------------------------------------------------------ Please reply me as soon as possible. Regards Navneet

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          The BLOB type in your database seems limited to 64KB. There may be a larger type though. Example: MySQL has TINYBLOB, MEDIUMBLOB, BLOB, and LONGBLOB. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read formatted code with indentation, so please use PRE tags for code snippets.


          I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


          1 Reply Last reply
          0
          • S Simon_Whale

            what database are you using?

            Marc Clifton wrote:

            That has nothing to do with VB. - Oh crap. I just defended VB!

            N Offline
            N Offline
            navneet professional
            wrote on last edited by
            #5

            Hi, I am using Interbase 6.0 database. My database table structure is like: Create table "TEST" ( "NAME" VARCHAR(10), "BLOB_DATA" BLOB ) Interbase 6.0 database only supports BLOB for storing images.It don't support LONGBLOB & other datatypes.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups