Re: Tryout mysql++ Example Loading binary file in a BLOB ... ... to be continued in msql++ list !?

2002-09-24 Thread Franz Alt

I think I'll start this thread in mysql++ list again.

Sorry, I might was to tired yesterday...





-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Tryout mysql++ Example Loading binary file in a BLOB ...

2002-09-23 Thread Franz Alt

I wanted to test the mysql++ example Loading binary file in a BLOB ...
because I'm looking for for a solution to load several MB up to a remote DB,
without FTP or things like that. Just 1 thread in DB, so performance should
be no problem.

Therefor I try to execute and benchmark this quite famous Code from the
online-manual, but I've got some Problems (P) and Questions (Q).
I'm using Visual C++ 6 on an Windows98 , 526MHz and 320MB Ram.

I can compile in debug and release-Version. No errors, just warnings like, I
try to translate:
\include\type_info1.hh(39) : warning C4800: 'int' : Variable wird auf
booleschen Wert ('True' oder 'False') gesetzt

Integer set to boolean value true or false
\include\convert1.hh(40) : warning C4273: 'strtol' : Inkonsistente
DLL-Bindung. dllexport angenommen.

assumed inconsistent dll-binding for dllexport
\include\sql_query1.hh(135) : warning C4355: this' : wird in
Initialisierungslisten fuer Basisklasse verwendet

-this is used in init-lists for derived classses
\load_file.cpp(5) : warning C4273: '_errno' : Inkonsistente DLL-Bindung.
dllexport angenommen.

assumed inconsistent dll-binding

Q1: Can I do something against this warnings?
Q2:  or are they taking any affect?

Then something curious: I can execute the code in Release-Mode and it runs
with no runtime error ( but the result is wrong , see below).

P1: When I run in in debug-Mode, I get an SQL-Syntax-Error 1064

Q3: Where can I find error-codes in the online-manual?

Q4: I'm not shure if std::string fill(read_buffer,blen);I included
std::string

P2:Unfortunally, the result ist not ok, since the escape manipulator
doesn't seem to do anything at all.

P3: I tried to fix the code for my VisualC++ compiler by inserting
#include string iostream , using namespace std;  or adding std::
for debug-mode.
 Then I get (often, not always) an Exception in line:
  std::string tmp_str = strbuf.str();
release binary seems to be unchanged ...

This is a sample output of 2 runnings. file aaa contains now data to
escape, but abs does. both are ascii files.

// - OUTPUT
1st
C:\Bauinfo\Projekt_MySQL\mmd_source\Konsolentest\mysql_blob_load\Releasel
abc
release: loading ... abc
load data file: 0s
Length:20
kBytes/second: 1.#INF
// the cout of the whole query
INSERT INTO blobs (blob_data) VALUES(abc / 1 ' 2   3\
)
Error: You have an error in your SQL syntax near '3\
)' at line 1 1064

2nd
C:\Bauinfo\Projekt_MySQL\mmd_source\Konsolentest\mysql_blob_load\Releasel
aaa
release: loading ... aaa
load data file: 0s
Length:28
kBytes/second: 1.#INF

INSERT INTO blobs (blob_data) VALUES(aaa bbb !§$%() 123  x-_
)
INSERT in MySQL: 0s
Length:28
kBytes/second: 1.#INF
//  END OF OUTPUT


P3) Uploaded Binary files cause no SQL-error, but are cut at the first '\0'.
therefore only some bytes are stored in BLOB (messured via phpmyadmin,
SELECT length(blob_data) ...


Has anybody compiled and tried out the original example?


now a last, my lightly changed code:
--

#include windows.h
#include sys/stat.h
#include fstream
#include sqlplus.hh
extern int errno;

#include iostream
#include string


// Für Zeittests

#define _PERFORMANCE

#include time.h
#include cstdlib
#include vector
#include algorithm

#include conio.h

using namespace std;

const char  MY_HOST[]=localhost;
const char  MY_USER[]=franz;
const char  MY_PASSWORD[]=fff123;

const char  MY_DATABASE[]=blobtest;
const char  MY_TABLE[]=blobs;
const char  MY_FIELD[]=blob_data; // BLOB field

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


#ifdef _DEBUG // compiled for debugging
  std::string datei = aaa;
  cout  debug: loading ...   datei endl;
  // argc=2;
#endif

#ifndef _DEBUG  // compiled for release
   std::string datei = argv[1];
 if (argc  2) {
  cerr  Usage : load_file full_file_path  endl  endl;
  return -1;
 }
 cout  release: loading ...   datei endl;
#endif

  Connection con(use_exceptions);
 try {
  con.real_connect
(MY_DATABASE,MY_HOST,MY_USER,MY_PASSWORD,3306,(int)0,60,NULL);
  Query query = con.query();
  std::ostrstream strbuf;
  std::ifstream In (datei.c_str(),ios::in | ios::binary);
  struct stat for_len;
  if ((In.rdbuf())-is_open()) {
   if (stat (datei.c_str(),for_len) == -1) return -1;
   unsigned int blen = for_len.st_size;  if (!blen) return -1;

#ifdef _PERFORMANCE
 // Performance Test
 clock_t Start, End;
 double Elapsed;
 Start = clock();
#endif

 char  *read_buffer = new char[blen];
 In.read(read_buffer,blen);
 std::string fill(read_buffer,blen);

#ifdef _PERFORMANCE
 End = clock();
 Elapsed = static_castdouble ( End - Start ) / CLOCKS_PER_SEC ;
 cout  \load data file:\   Elapsed  s  endl;
 cout  Length: blen  endl;
 cout  Bytes/second:   blen / Elapsed  endl;

 // 2nd Performance Test
 Start = clock();
#endif
   strbuf   INSERT INTO   MY_TABLE   (  MY_FIELD  )
VALUES(\   escape  fill   \);
   std::string tmp_str = strbuf.str();  // to have variable in debugger
available
   int l = tmp_str.length();
   cout  endl