Showing posts with label MYSQL. Show all posts
Showing posts with label MYSQL. Show all posts

2018/08/21

Build Poco 1.9.0 with OpenSSL and MySQL

오랜만에 Poco 라이브러리 1.9 버전을 빌드해 보았다.
얼마전부터 계속 시도해 보았지만 OpenSSL을 포함하는데 문제가 있어서 계속 실패를 하다가 인터넷을 통해 도움을 얻어 드디어 성공하였다.
일단 Poco 라이브러리의 추가 포함 라이브러리는 목적에따라 OpenSSL과 MySQL을 추가할 수 있다.
언제든 사용할 수 있는 라이브러리라서 빌드할 때 이들을 추가해 놓으면 편할 것 같아서 항상 이를 포함하여 빌드한다.

우선 빌드에 필요한 것들은 다음과 같다.
Poco Library 1.9
https://github.com/pocoproject/poco
poco-poco-1.9.0-release.zip
OpenSSL
https://github.com/pocoproject/openssl
openssl-develop.zip
MySQL
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
mysql-5.7.23-win32.zip
mysql-5.7.23-winx64.zip

OpenSSL 빌드하기
https://github.com/pocoproject/openssl 에서 받은 소스를 빌드한다.
이미 Vsiual Studio 2013 버전으로 빌드가 되어있는 dll과 라이브러리가 소스에 포함되어있어 이를 이용하는 경우 빌드를 할 필요가 없다.
혹시 OpenSSL 버전을 변경하고자 하는경우 다시 빌드를 해야한다.
2018년 08월 17일 현재 올려져있는 버전은 1.1.0g 버전이다.
새롭게 빌드를 하고자 하는경우 소스를 압축해제하고 해제한 폴더에서 다음 명령을 수행하면 된다.
build.ps1을 실행하면 된다.
build.ps1 명령을 아래와 같은 형식이고,
build.ps1 [-openssl_release 1.0.0 | 1.1.0]
          [-vs_version 150 | 140 | 120 | 110 | 100 | 90]
          [-config     release | debug | both]
          [-platform   Win32 | x64] # TODO WinCE/WCE
          [-library    shared | static | both]
       
실행 예제는 다음과 같다.       
powershell -ExecutionPolicy RemoteSigned -File build.ps1 -openssl_release 1.1.0h -vs_version 120 -config both -platform x64 -library both

빌드를 하면 소스 경로에 VC_(버전번호) 의 폴더가 만들어지고 그 안에 결과 파일들이 생성된다.

Poco 추가 라이브러리 구성하기
먼저 Poco 라이브러리 소스 파일(poco-poco-1.9.0-release.zip)을 압축해제한다.
그리고 OpenSSL을 빌드를 하지 않은경우 openssl-develop.zip 파일의 build 폴더를 Poco 소스의 openssl 폴더에 복사한다.
OpenSSL을 빌드하였다면 결과 폴더(VC_(버전번호))를 openssl 폴더에 복사하고 이름을 build로 변경한다.

Poco 소스 폴더에 mysql 폴더를 생성하고 mysql-5.7.23-win32.zip 파일의 include 와 lib 폴더를 압축해제하고 lib 폴더는 lib32로 변경한다.
그리고 mysql-5.7.23-winx64.zip 파일의 lib 폴더를 mysql 폴더에 압축해제하고 lib64로 변경한다.
그러면 최종적으로 추가 생성된 폴더는 아래와 같은 구성된다.
poco-poco-1.9.0-release
openssl
build
include
openssl
win32
bin
lib
win64
bin
lib
mysql
include
lib32
lib64

빌드를 하기전에 buildwin.cmd 파일에서 위에서 구성한 mysql 폴더를 사용하도록 변경을 해 주어야한다.
PLATFORM 파라메터를 인식한 후에 아래 코드를 추가(62line)한다.
rem MySQL
set MYSQL_DIR=%POCO_BASE%\mysql
set MYSQL_INCLUDE=%MYSQL_DIR%\include
if "%PLATFORM%"=="Win32" (set MYSQL_LIB=%MYSQL_DIR%\lib32)
if "%PLATFORM%"=="x64" (set MYSQL_LIB=%MYSQL_DIR%\lib64)
set INCLUDE=%INCLUDE%;%MYSQL_INCLUDE%
set LIB=%LIB%;%MYSQL_LIB%

echo MySQL Path: %MYSQL_DIR%
echo Include: %INCLUDE%
echo Lib: %LIB%
pause

echo 명령과 pause 명령은 mysql 관련 설정이 제대로 되었는지 확인하기 위해 넣은 코드이다.

이제 Visual Studio 버전에 맞는 빌드 명령을 호출하면 된다.
buildwin.cmd 명령 형식은 다음과 같다.
Usage:
------
buildwin VS_VERSION [ACTION] [LINKMODE] [CONFIGURATION] [PLATFORM] [SAMPLES] [TESTS] [TOOL]
VS_VERSION:    "90|100|110|120|140|150"
ACTION:        "build|rebuild|clean"
LINKMODE:      "static_mt|static_md|shared|all"
CONFIGURATION: "release|debug|both"
PLATFORM:      "Win32|x64|WinCE|WEC2013"
SAMPLES:       "samples|nosamples"
TESTS:         "tests|notests"
TOOL:          "devenv|vcexpress|wdexpress|msbuild"

아래 명령은 Visual Studio 2013 버전으로 빌드하기 위해 실행한 명령이다.
buildwin.cmd 120 build all both x64 samples tests msbuild

빠르게 빌드만 하려면 SAMPLES과 TESTS에 대하여 nosamples 와 notests로 설정하여 빌드한다.

2016/05/11

MySQL 5.7 Manual Install

MySQL 최신 버전인 5.7 버전을 테스트할 일이 있어서 수동으로 설치해 보았는데 이전과 다른 사항이 있어 기록차원에서 정리하였다.

우선 설치에 필요한 압축 파일을 mysql.com 사이트로 부터 다운로드 받는다.
내가 받은 파일은 mysql-5.7.12-winx64.zip 이다. 이 파일을 특정 폴더에 압축을 풀어 놓는다.
여기에서는 E:\Dev\mysql-5.7.12-winx64 압축을 풀어 놓고 기록 하였다.

설정 파일 작성
설정 파일을 작성해야 하는데 압축해제 폴더의 my-default.ini 파일은 my.ini로 복사하여 편집한다.
# These are commonly set, remove the # and set as required.
basedir = E:\Dev\mysql-5.7.12-winx64
datadir = E:\Dev\mysql-5.7.12-winx64\data
port = 3316
# server_id = .....
basedir과 datadir을 필수이고 port는 필요시 지정 한다. 다른 MySQL을 운영으로 인해 또는 다른 이유로 인해 기본 포트인 3306을 사용하지 못하는 경우 다른 포트 입력한다.

환경 변수 등록
압축 해제 폴더를 시스템 환경 변수에 MYSQL_HOME 으로 등록한다. 임시로 사용하는 것으로 시스템 환경설정이 부담스러운 경우 도스창에서 mysqld 를 실행하기전에 아래 명령으로 환경변수 등록 한다.
E:\Dev\mysql-5.7.12-winx64\bin> set MYSQL_HOME = E:\Dev\mysql-5.7.12-winx64

MySQL  초기화
E:\Dev\mysql-5.7.12-winx64\bin> mysqld --initialize
위 명령으로 지정한 data 폴더에 필요한 파일 생성 된다. 혹시 실패한 경우 data 폴더의 내용을 모두 삭제하고 위 명령을 다시 수행한다.

권한 설정을 위한 데몬 실행
--skip-grant-tables 옵션으로 권한 설정을 무시하도록 데몬을 실행한다.
E:\Dev\mysql-5.7.12-winx64\bin> mysqld --skip-grant-tables

MySQL 접속
mysql.exe 실행파일을 이용하여 MySQL에 접속한다.
E:\Dev\mysql-5.7.12-winx64\bin> mysql -u root --port=3316
접속시 포트번호 지정은 설정에서 기본 포트인 3306을 사용하지 않고 다른 포트를 사용할 경우 입력한다.

root 암호 설정
--skip-grant-tables 옵션으로 인해 ALTER USER나 SET PASSWORD 명령을 사용할 수없어 mysql 데이터베이스에 접속하여 User 테이블을 직접 수정한다.
mysql> \u mysql
Database changed
mysql> UPDATE USER SET authentication_string = password('mypassword') WHERE user = 'root';

mysql 재시작
서비스 등록하지 않은 경우 Task Manager에서 mysqld 종료 후 --skip-grant-tables 옵션 없이 다시 시작 한다.
E:\Dev\mysql-5.7.12-winx64\bin> mysqld

MySQL 접속
위에서 설명한 방법으로 MySQL에 접속한다.

root 암호 재설정
위에서 root의 암호를 바꾸서 접속에 성공했음에도 불구하고 데이터베이스 선택 명령을 실행하면 아래와 같이 명령을 수행하기 전에 암호를 설정하로는 에러 메시지가 출력 된다.
RROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

아래 방법을 이용하여 root 암호를 다시 설정 한다.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'mypassword';
또는
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypassword');

아래 사항은 필수 사항은 아니고 알아두면 나쁘지 않을 서비스 등록에 대한 내용이다.
mysql 서비스 등록또는 삭제
서비스 등록: E:\Dev\mysql-5.7.12-winx64\bin> mysqld --install [서비스이름]
서비스 삭제: E:\Dev\mysql-5.7.12-winx64\bin> mysqld --remove [서비스이름]
서비스 이름이 지정되지 않으면 기본적으로 'MySQL'로 서비스 등록 시도

서비스 시작: net start mysql
서비스 중지: net stop mysql

2016/05/03

Poco Library 빌드하기

얼마전에 공개된 Poco Library v1.7.3 버전을 빌드해 보았다.
배포되는 Poco Library 중 poco-1.7.3-all.zip 을 다운 받았다. 이 버전은 OpenSSL과 MySQL Client 라이브러리를 필요로 한다.

Poco Library 빌드를 위한 파일은 아래와 같다.
Poco Library
http://pocoproject.org/releases/poco-1.7.3/poco-1.7.3-all.zip
OpenSSL
https://slproweb.com/products/Win32OpenSSL.html
https://slproweb.com/download/Win32OpenSSL-1_0_2g.exe
https://slproweb.com/download/Win64OpenSSL-1_0_2g.exe
MySQL
32-bit ZIP Archive(http://dev.mysql.com/downloads/file/?id=462038)
64-bit ZIP Archive(http://dev.mysql.com/downloads/file/?id=462039)

우선 poco-1.7.3-all.zip 파일을 특정 경로에 압축을 해제 한다. 압축 해제  후 존재하지 않는 폴더 Bin, Bin64, Lib, Lib64를 생성한다. 여기서는 D:\poco-1.7.3-all 에 압축을 해제한 것으로 간주하고 기록 하였다.
Win32OpenSSL-1_0_2g.exe 설치후 설치 경로의 bin 폴더의 libeay32.dll, ssleay32.dll파일을 Bin 폴더에 복사하고 lib 폴더의 libeay32.lib, ssleay32.lib파일을 Lib 폴더에 복사한다. 그리고 lib/VC/static 폴더의 모든파일을 Lib 폴더로 복사한다.
Win64OpenSSL-1_0_2g.exe 파일의 경우 Bin64와 Lib64 폴더로 복사를 한다. 마지막으로 include 폴더의 openssl 폴더를 D:\poco-1.7.3-all\Crypto\include 폴더에 복사한다.

MySQL에 포함되어 있는 include 폴더의 모든 파일들을 D:\poco-1.7.3-all\Data\MySQL\include 복사하고 32비트 파일에 포함되어 있는 libmysql.dll파일과 libmysqld.dll 파일을 Bin 폴더로 libmysql.lib파일과 libmysqld.lib 파일을 Lib 폴더로 복사한다. 64비트 파일에 포함되어 있는 파일들은 각각 Bin64와 Lib64로 복사한다.

마지막으로 buildwin.cmd 파일을 열어 편집 한다.
수정해야할 내용은 set OPENSSL_LIB 부분으로 32비트 버전을 빌드 할 때에는 D:\poco-1.7.3-all\Lib 로 설정하고 빌드하고 64비트로 빌드 할 때에는 D:\poco-1.7.3-all\Lib64로 설정하고 빌드 한다.

이렇게 설정하고 아래와 같이 sample과 test프로젝트를 제외하고 빌드한다.
32bit: D:\poco-1.7.3-all\buildwin 110 build all both Win32 nosamples notests devenv
64bit: D:\poco-1.7.3-all\buildwin 110 build all both x64 nosamples notests devenv

buildwin 실행 결과 32비트와 64비트 모두 에러 없이 빌드를 마쳤고 dll과 lib 파일이 생성 되었다.

2011/01/28

Firebird는 Transaction 처리가 기본!!

요즘 Firebird 를 공부하고 있다. 조금은 당황스러운 경험을 하였다.



Firebird 설치시 포함되어 있는 Interactive SQL(isql.exe) 을 이용하여 몇가지 테스트를 하였다. 두 개의 isql 인스턴스를 실행하고 하나의 데이터베이스 연결을 하였다.




A isql 인스턴스(이하 A) 에서 테이블을 하나 생성 하였다. 그리고 B isql 인스턴스(이하 B)에서 데이블이 존재하는지 SHOW TABLE 명령을 확인해 보니 존재 하는 것으로 보였다. 이 것이 DDL은 자동으로 commit 이 되어 그러는 것으로 알았다. 나중에 알게되었지만 DDL 이라도 isql 환경 설정에서 AutoDDL 을 off 로 두면 자동으로 commit 이 수행되지 않는다.




B 에서 방금 생성한 member 테이블에 데이터가 있는지 확인(SELECT * FROM member;)하여 보았다. 데이터가 없음을 확인하고 A 에서 member 테이블에 데이터를 Insert 하고 B 에서 확인을 하였다. B 에서는 아무런 데이터가 확인 되지 않았다. 당연한 결과로 A 에서 작업을 한 후 commit 을 하지 않았기 때문에 B 에서 확인할 수 없었다. A 에서 commit 을 한 후 B 에서 확인을 해 보아도 보이지 않았다. 이상한 일이였다. B 에서 commit 명령을 내리고서야 A 에서 작업한 내용을 확인할 수 있었다.




이 상황이 잘 이해가 되지 않았다. A 에서 작업(Transaction)이 commit 이 되면 B 에서 당연히 확인이 되어야 하는 것으로 생각을 하였다. 이 상황이 잘 못 된 것인줄 알고 MySQL 의 InnoDB 를 이용하여 Transaction 테스트를 해 보았지만 MySQL 는 나의 예상대로 동작을 하였다.




답을 찾아 헤메던 중 외국의 firebird community 에서 도움을 얻어 이유를 알았다. 예전에 오라클을 공부할 때 들었던 관계형 데이터베이스의 ACID 특성에 대해서 다시 듣게 되었다.

B 에서 A 의 작업이 확인되지 않은 이유는 B 에서 데이터를 확인하기 위해 DML(select)을 수행하면서 B 에서 transaction 이 시작 되었고 transaction 이 시작되면서 ACID 의 Isolation 특성으로 데이터베이스는 transaction 이 시작할때의 상태를 독립적으로 유지하게 되어서 B 의 transaction 이 commit 된 후에 A 에서 가한 데이터베이스의 변경된 사항을 확인할 수 있었던 것이였다. mysql 에서도 이러한 관점에서 다시 테스트를 해 보니 동일한 결과를 얻을 수 있었다.




일반적인 GUI 프로그램을 사용하게 되면 Transaction 관리를 하기 때문에 개별적인 작업에 대한 적용이 이루어지는 것이다.




Firebird 란 놈을 좀 더 공부해 보아야겠다. Open Source 정책으로 운영되고 사용자 층이 두텁지 않아서 자료가 많이 부족해서 공부하기가 어렵다.<

Original Post : http://neodreamer-dev.tistory.com/495

2011/01/26

InnoDB 지원 여부 확인하기 및 생성하기

mysql> show variables like 'have_innodb';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_innodb | YES |
+---------------+-------+
1 row in set (0.00 sec)

mysql>CREATE TABLE customers (a INT, b CHAR (20), INDEX (a)) ENGINE=InnoDB;
<

Original Post : http://neodreamer-dev.tistory.com/494

2009/08/27

MySQL 버전 확인 질의문

/* Version */
mysql> SELECT VERSION();
+---------------------+
| VERSION() |
+---------------------+
| 5.0.67-community-nt |
+---------------------+
1 row in set (0.00 sec)

Original Post : http://neodreamer-dev.tistory.com/313

MySQL Connection 확인하기

Connection 상태 확인하기

/* Process List */
mysql> SHOW FULL PROCESSLIST;
+----+------+-----------------+-------------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------------+-------------+---------+------+-------+-----------------------+
| 65 | root | localhost:60206 | server | Sleep | 246 | | NULL |
| 67 | root | localhost:61278 | NULL | Query | 0 | NULL | SHOW FULL PROCESSLIST |
+----+------+-----------------+-------------+---------+------+-------+-----------------------+
2 rows in set (0.00 sec)



Connection 수 확인하기

/* Connected thread count */
mysql> SHOW STATUS LIKE 'Threads_connected';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 2 |
+-------------------+-------+
1 row in set (0.00 sec)




동작중인 Connection 수 확인하기

/* Running thread count */
mysql> SHOW STATUS LIKE 'Threads_running';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| Threads_running | 1 |
+-----------------+-------+
1 row in set (0.00 sec)

Original Post : http://neodreamer-dev.tistory.com/312

2009/04/22

드디어!! MySQL Connector/C++ 1.0.5 GA 릴리즈

Preview 버전을 공개한지 8개월 만에 정식판을 공개 하였다.

Preview 버전부터 소스를 컴파일 하여 프로젝트에 사용해 왔는데 MySQL C API 를 사용하는 것 보다 사용하기 편하였다.

JDBC 구조를 사용하여 JDBC를 사용해 본 사람에게는 보 다 더 가깝께 느껴질 수 있다.

1.0.4 Beta 버전 부터 각 플랫폼의 컴파일러 마다 생성된 Binary를 지원해서 소스를 컴파일 해서 사용해야하는 불편이 사라졌다.

그전에는 정적라이브러리에서 문제가 있어 보였는데 정식판을 어떠한지 확인을 해 보아야 겠다.


MySQL Connector/C++ 1.0.5 GA (21.04.2009)

  • Changed the interface of sql::ConnectionMetaData, sql::ResultSetMetaData and sql::ParameterMetaData to have a protected destructor. In this way the client code doesn't need, and won't be able, to destruct the metadata objects returned by the connector. The connector will handle their destruction. This enables statements like: connection->getMetaData->getSchema(); without the result of leaking memory because we lost the pointer returned by getMetaData(). (Lawrin, Andrey)

  • Large overhaul of the code to improve the memory management to not leak in exceptional situations. Big improvement compared to Beta1. (Andrey)

  • Fixed the interface of sql::Driver and sql::Connection so they accept the options map by alias instead of by value. (Andrey)

  • Changed the return type of sql::SQLException::getSQLState() from std::string to const char
  • to be consistent with std::exception::what(). (Andrey)

  • Implemented getResultSetType() and setResultSetType() for Statement. Used are TYPE_FORWARD_ONLY, which means unbuffered result set and TYPE_SCROLL_INSENSITIVE, which means buffered result set. (Andrey)

  • Implemented getResultSetType() for PreparedStatement. The setter is not implemented because currently PreparedStatement can't do refetching and storing the result means the bind buffers will be correct. (Andrey)

  • Added "defaultStatementResultType" to MySQL_Connection::setClientOption() as an option. Also the method now returns `sql::Connection *`. (Andrey)

  • Added Result::getType() and implemented it in the three result set classes.(Andrey)

  • Enabled tracing functionality when building with VC8 and up (VS2005 and up). (Andrey)

  • Added better support for named pipes, on Windows. Use pipe:// and add the path to the pipe. Shared memory connections are currently not supported. (Andrey)

  • Fixed a bug in MySQL_Connection::setSessionVariable() which led to exception being thrown. (Andrey)



MySQL Connector/C++ Wiki
MySQL Connector/C++ Download
Original Post :
http://neodreamer-dev.tistory.com/295

2009/04/01

MySQL 매뉴얼에 포함되어 있는 Connector/C++ 이용한 프로그램 작성

필요할 때가 있을 것 같아서 접근하기 쉽도록 MySQL 매뉴얼에 포함되어 있는 Connector/C++ 컴파일 방법을 스크랩 하였다.



20.6.3. MySQL Connector/C++ Building applications on Windows



MySQL Connector/C++ is available as a static or dynamic library to use with your application. This section looks at how to link the library to your application.



Static library



The MySQL Connector/C++ static library file is mysqlcppconn-static.lib. This needs to be statically linked with your application. You also need to link against the files libmysql.dll and libmysql.lib. Once linking has been successfully completed, the application will require access to libmysql.dll at run time.



Dynamic library



The MySQL Connector/C++ dynamic library file is mysqlcppconn.dll. In order to build your client application you need to link it with the file mysqlcppconn.lib. At run time the application will require access to the files mysqlcppconn.dll and libmysql.dll.



Building an application using the static library - step-by-step


  • Select File, New, Project from the main menu. Then in the wizard select Visual C++, Win32. From Visual Studio Installed Templates select the application type Win32 Console Application. Enter a name for the application, and then click OK, to move to the Win32 Application Wizard.


  • In the Win32 Application Wizard, click on Application Settings and ensure the defaults are selected. The radio button Console application, and the checkbox Precompiled headers will be selected.


  • From the drop down list box on the toolbar, change from the default Debug build to the Release build.


  • From the main menu select Project, Properties. This can also be accessed using the hot key ALT + F7.


  • Under Configuration Properties, open the tree view.


  • Select C++, General in the tree view. Then in the Additional Include Directories text field, add include/.


  • In the same tree view under Linker, General, add lib/opt into the Additional Library Directories text field.


  • Also in Linker, General, Additional Library Directories, add MySQL Server lib/opt for libmysql.lib.


  • Then in Linker, Input, Additional Dependencies, enter mysqlcppconn-static.lib and libmysql.lib.

      ------ Rebuild All started: Project: cpp_static_client, Configuration:  Release Win32 ------
    Deleting intermediate and output files for project 'cpp_static_client', configuration 'Release|Win32'
    Compiling...
    cpp_static_client.cpp
    stdafx.cpp
    Linking...
    cpp_static_client.obj : error LNK2001: unresolved external symbol __imp__get_driver_instance
    cpp_static_client.obj : error LNK2001: unresolved external symbol "__declspec(dllimport)
    public: int __thiscall sql::SQLException::getErrorCode(void)const "
    (__imp_?getErrorCode@SQLException@sql@@QBEHXZ)
    cpp_static_client.obj : error LNK2001: unresolved external symbol "__declspec(dllimport)
    public: class std::basic_string,
    class std::allocator > const & __thiscall
    sql::SQLException::getSQLState(void)const "
    (__imp_?getSQLState@SQLException@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
    C:\Dokumente und Einstellungen\T60\Eigene Dateien\Visual Studio 2008\Projects
    \cpp_static_client\Release\cpp_static_client.exe : fatal error LNK1120: 3 unresolved externals
    Build log was saved at "file://c:\Dokumente und Einstellungen\T60\Eigene Dateien\Visual Studio 2008\
    Projects\cpp_static_client\cpp_static_client\Release \BuildLog.htm"
    cpp_static_client - 4 error(s), 0 warning(s)



  • In the Project, Properties tree view, under C++, Preprocessor, enter CPPCONN_PUBLIC_FUNC= into the Preprocessor Definitions text field.




Building an application to use the dynamic library - step-by-step




  • From the main menu select File, New Project. Then in the wizard select Visual C++, Win32. Under Visual Studio installed templates select Win32 Console Application. Enter a suitable name, and then click OK to enter the Win32 Application wizard.


  • In the Win32 Application Wizard, click on Application Settings. Use the default settings. The Console application radio button, and Precompiled header checkbox should be selected. Click Finish to close the wizard.


  • From the drop down list box on the toolbar, change from the default Debug build to the Release build.


  • From the main menu select Project, Properties. This can also be accessed using the hot key ALT + F7.


  • Under Configuration Properties, open the tree view.


  • Under C++, General, add include/ into the Additional Include Directories text field.


  • Under Linker, General, add lib/opt into the Additional Library Directories text field.


  • Under Linker, Input, add mysqlcppconn.lib into the Additional Dependencies text field.


  • In the Editor, copy standalone_example_docs1.cpp, and add #include "stdafx.h" at the top of the file.


  • From the main menu select Build, Build Solution, to build the solution.


  • Open a command prompt by selecting Start, Execute, and entering cmd. Go to the build directory for the project, and change into the Release directory.


  • Run the application. You will receive an error: “cannot find mysqlcppconn.dll”.


  • Copy mysqlcppconn.dll to the working directory or extend the PATH environment variable using SET PATH=%PATH%;C:\path\to\cpp. Alternatively, you can copy mysqlcppconn.dll to the Windows installation Directory, typically c:\windows.
    Original Post : http://neodreamer-dev.tistory.com/282

MySQL Connector/C++ 1.0.4 beta Library 정식 배포




Connector/C++ 이 Alpha 딱지를 떼고 Beta 딱지를 붙이고나서 드디어 정식으로 라이브러리 제공을 시작하였다.

1.0.4 버전 이전에는 소스를 받아서 필요한 플랫폼에서 컴파일을 해서 직접 라이브러리를 만들어서 사용해야했는데 이제는 각각의 운영체제에 맞는 라이브러리를 제공한다.

현재(2009/04/01) 지원하는 운영체제는 다음과 같다.
  • Windows
  • Windows x64
  • Linux (non RPM packages, glibc-2.3)
  • Red Hat Enterprise Linux 5 (non RPM packages)
  • Red Hat Enterprise Linux 4 (non RPM packages)
  • SuSE Linux Enterprise Server 9 (non RPM packages)
  • SuSE Linux Enterprise Server 10 (non RPM packages)
  • Solaris (TAR packages)
  • FreeBSD (TAR packages)
  • Mac OS X (TAR packages)
  • HP-UX (TAR packages)
  • AIX (TAR packages)

라이브러리를 직접 배포하니 신뢰도 또한 더 높으리라 생각 된다. 직접 라이브러리를 만들어 사용할 때는 정적라이브러리에서 링크문제로 사용하지 못했는데 정식 버전은 어떤지 테스트 해 봐야 겠다. 그리고 C++ Builder 에서도 사용 가능한지도 테스트 해 봐야 겠다.

Connector/C++ Download Page

Download Connector/C++ 1.0.4 beta Windows MSI Installer (x86)
Download Connector/C++ 1.0.4 beta Without installe (x86)
Download Connector/C++ 1.0.4 beta Windows MSI Installer (AMD64 / Intel EM64T)
Download Connector/C++ 1.0.4 beta Without installe (AMD64 / Intel EM64T)

Original Post : http://neodreamer-dev.tistory.com/281

2009/03/31

MySQL Connector/C++ 1.04 beta 버전이 공개 되었다.

기나긴 Alpha 딱지를 떼고 Beta 딱지를 붙이고 나왔다.

공개된 일정데로라면 다음 버전인 1.05 버전에서 Beta 딱지도 떼고 정식이 된다.

이번 버전에서 바뀐 점은 아래와 같다. (출처: MySQL site)


  • Prepared support for upcoming Connector/C. (Georg)

  • Added Windows GUI (MSI) installer (Georg)

  • Bumping up CMake minimum version requirement from 2.4.2 to 2.6.2. We need the latest version for Windows. (Lawrin)

  • Added "metadataUseInfoSchema" to connection propery map which allows you to control the use of the INFORMATION_SCHEMA for meta data. (Andrey)

  • Fixed a bug in all implementations of ResultSet::relative() which was giving wrong return value although positioning was working correctly. (Andrey)

  • Fixed a leak in MySQL_PreparedResultSet when the result was containing a BLOB column. Andrey)

  • Implemented MySQL_ConnectionMetaData::supportsConvert(from, to). (Andrey)

  • Introduced sql::DataType::YEAR to complement MySQL's YEAR type. (Andrey)

  • Introduced PreparedStatement::getMetaData(). (Andrey)

  • Introduced ResultSetMetaData::isZerofill(), which is not in the JDBC specification. (Andrey)

  • Fixed all implementations of ResultSet::isNull() to check whether the current position is on a real row, not isBeforeFirst() nor isAfterLast(), like all getXXX methods do. (Andrey)

  • Implementation for MySQL_DatabaseMetaData::getProcedures() when INFORMATION_SCHEMA is asked not to be used. (Andrey)

  • Removed MySQL_DatabaseMetaData::getProcedureColumns() from the interface. Until now it was returning always an empty result set. Full implementation will be added at a later stage. (Andrey)

  • Changed a bunch of methods of DatabaseMetaData()::getXXX, which returned `int` to return `unsigned int` because it makes more sense. (Andrey)


이번 버전 부터는 윈도우즈 상에서 Installer 를 지원한다. 어떤 형식으로 설치가 되는지는 실험을 해 봐야겠다.

MySQL Connector/C++
MySQL Connector/C++ Download
Original Post :
http://neodreamer-dev.tistory.com/276

2009/03/03

MySQL Connector/C++ 1.0.3 Alpha Released!!

MySQL 의 C++ Connector 가 1.0.3 Alpha 버전이 공개 되었다.

MySQL Connector/C++ 1.0.3 Alpha (03.03.2009)


  • Added new tests at test/unit/classes. Those tests are mostly about code coverage. Most of the actual functionality of the driver is tested by the tests found at test/CJUnitPort. (Ulf)

  • New data types added to the list returned by DatabaseMetaData::getTypeInfo(): FLOAT UNSIGED, DECIMAL UNSIGNED, DOUBLE UNSIGNED. Those tests may not be in the JDBC specification. However, due to the change you should be able to look up every type and type name returned by, for example, ResultSetMetaData::getColumnTypeName(). (Andrey)

  • MySQL_Driver::getPatchVersion introducted. (Andrey)

  • Major performance improvements due to new buffered resultset implementation by Andrey. (Ulf)

  • Addition of test/unit/README with instructions for writing bug/regression tests. (Ulf)

  • Experimental support for STLPort. This feature may be removed again at any time later without prior warning! Check cmake -L for configuration instructions. (Andrey)

  • Fixed a bug in MySQL_PreparedResultSet::getString(). Returned string had real data but the length was random. Now, the string is initialized with correct length and thus is binary safe. (Andrey)

  • Added properties-enabled (map of key->value) methods for connecting, which add many connect options. (Andrey)

    o Driver::connect( map )

    o Connection::Connection( map )

  • New BLOB implementation. Got rid of sql::Blob in favor of std::istream. C++'s IOStream library is very powerful, similar to PHP's streams. It makes no sense to reinvent the wheel. For example one can pass a std::istringstream object to setBlob() if the data is in memory, or just open a file std::fstream and let it stream to the DB, or write own stream. Similar will be true for getBlob() where we can just copy data, if buffered result set, or stream, if we implement it. (Andrey)

  • Implemented ResultSet::getBlob() which returns std::stream. (Andrey)

  • Fixed MySQL_DatabaseMetaData::getTablePrivileges() to work correctly. Test cases added in the first unit testing framework. (Andrey)

  • Implemented MySQL_Connection::setSessionVariable() for setting variables like sql_mode. (Andrey)

  • Implemented MySQL_DatabaseMetaData::getColumnPrivileges(). (Andrey)

  • cppconn/datatype.h changed and used again. Reimplemented the type subsystem to be more usable - more types for binary and non-binary strings. (Andrey)

  • Implementation for MySQL_DatabaseMetaData::getImportedKeys() for MySQL versions before 5.1.16 using SHOW, and above using INFORMATION_SCHEMA. (Andrey)

  • Implemented MySQL_ConnectionMetaData::getProcedureColumns(). (Andrey)

  • make package_source packs now with bzip2. (Andrey)

  • Re-added getTypeInfo() with information about all types supported by MySQL and the sql::DataType. (Andrey)

  • Exchanged the implementation of MySQL_ConstructedResultSet to use more efficient non O(n) but O(1) access method. This should improve the speed with which the metadata result sets are used. Also, there is less copy during the construction of the result set, which means that all result sets returned from the metadata functions will be faster. (Andrey)

  • Introduced, internally, sql::mysql::MyVal which has implicit constructors used in mysql_metadata.cpp to create result sets with more native data instead of always string (varchar). (Andrey)

  • Renamed ResultSet::getLong() to ResultSet::getInt64(). resultset.h includes typdefs for Windows to be able to use int64_t. (Andrey)

  • Introduced ResultSet::getUInt() and ResultSet::getUInt64(). (Andrey)

  • Corrected handling of unsigned server types. Now returning correct values (Andrey)

  • Fixed handling of numeric columns in ResultSetMetaData::isCaseSensitive to return false. (Andrey)

  • Better implementation for ResultSetMetaData::isReadOnly. Values generated from views are read-only. Seems that these generated values don't have `db` in MYSQL_FIELD set, while all normal columns do have. (Andrey)

  • Implemented MySQL_DatabaseMetaData::getExportedKeys(). (Andrey)

  • Implemented MySQL_DatabaseMetaData::getCrossReference(). (Andrey)


소스는 프로젝트 페이지에서 다운 받을 수 있다.

MySQL Connector/C++ Webpage
MySQL Connector/C++ 1.0.3 Download
Original Post :
http://neodreamer-dev.tistory.com/260

2008/12/25

std::string 의 날짜를 CTime에 넣기

MySQL의 DATE 함수에 의해 얻어진 std::string 문자열("YYY-MM-DD")을 CTime에 넣기.

        // "1999-01-01"
// "0123456789"
std::string d = "1999-01-01";

CTime time(
atoi( d.substr(0, 4).c_str() ), // Year
atoi( d.substr(5, 2).c_str() ), // Month
atoi( d.substr(8, 2).c_str() ), // Day
0, 0, 0 /* Time */ );


Original Post : http://neodreamer-dev.tistory.com/229

2008/12/22

MySQL Connector/C++ 1.0.2 Alpha Library

몇일 전 공개된 MySQL Connector/C++ 1.0.2 Alpha 버전을 컴파일 하여 DLL 과 라이브러리(Static 포함)를 만들었다. 컴파일러 버전은 Visual C++ 2005를 사용하였다.


진행 중인 프로젝트(32bit, 64bit)에 바로 적용을 하여 테스트 해보았는데 크게 문제가 되는게 없어 보였다.

테스트에 사용된 라이브러리는 MySQL 5.0.67 과 함께 컴파일한 라이브러리이다.



MySQL Connector/C++ 1.0.2 Source




With MySQL 5.0.67




With MySQL 5.1.30




Original Post : http://neodreamer-dev.tistory.com/226

2008/12/12

어영부영 뒷걸음질 치다가 버그 잡았다. MySQL Connector/C++ 에 판정승.. ^^*

어제 종일 씨름 했던 PreparedStatement 문제를 해결 하였다.

릴리즈 모드에서는 문제 없이 실행되던 prepared statement 가 디버그에서는 문제가 발생을 하여 디버그에서 릴리즈용 Library을 사용하여 시도를 해보았지만 다른 문제가 발생하였다.

Library를 새로 만들고 해봐도 해결되지 않다가 프로젝트 속성에서 MFC 라이브러리 사용을 정적으로 바꾸니 그제서야 동작을 하였다.

일단 문제 없이 실행이 되어서 계속진행을 할 수 있지만 왠지 찜찜하다. 짬 나는대로 자료 조사를 좀 해봐야겠다

Original Post : http://neodreamer-dev.tistory.com/218

2008/12/11

MySQL Connector/C++ 과 씨름하다 진이 다 빠졌다.

기본 MySQL C API 를 활용하였었는데 PreparedStatement 를 좀 더 깔끔하게 사용하기위해 MySQL Connector/C++을 사용을 시도해 보았다.

커넥션 관리나 질의문을 다루는 것에는 아무런 문제가 없이 잘 활용 할 수 있었으나 PreparedStatement 사용에 있어 문제가 발생하였다.

자꾸만 Error: 2036 (CR_UNSUPPORTED_PARAM_TYPE) 에러가 발생하였다. 같은 코드를 빈 프로젝트를 생성하여 테스트하면 아무런 문제가 없는데 실제 적용을 하려면 문제가 발생하였다.

라이브러리도 새로 만들어보고 디버그로 해보고 릴리즈모드로도 해보고 도대체 원인을 알 수 가 없었다.

조금만 더 지치면 MySQL++ 로 선회 해버릴 것 같다

Original Post : http://neodreamer-dev.tistory.com/217

사용자에게 모든 권한 주기


GRAND ALL PRIVILEGES ON *.* TO 'user'@'host';

Original Post : http://neodreamer-dev.tistory.com/215

Command 창에서 스크립트 실행하기

도스창에서 특정 SQL 스크립트 파일을 실행하는 방법이다.
요즘은 데이터베이스를 사용할 일이 많지 않아 자주 사용하는게 아니라서 인지 자꾸 잊어버린다.

C:\mysql\bin>mysql -u root -pPASSWORD DATABASENAME < script.sql

Original Post : http://neodreamer-dev.tistory.com/214

2008/12/09

MySQL 에서 현재 데이터베이스 이름 알아내기

MySQL 에서 핸재 사용중인 데이터베이스 이름을 알아내는 함수로 DATABASE() 를 제공하고 있고 select DATABASE() 하면 데이터베이스 이름을 가져올 수 있다.


Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select database();
+------------+
| database() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)

mysql> \u mysql
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| mysql      |
+------------+
1 row in set (0.00 sec)

mysql>
Original Post : http://neodreamer-dev.tistory.com/213

2008/12/03

MySQL Connector/C++ 을 이용한 간단한 테스트 소스

MySQL Connector/C++ 을 이용하여 간단하게 데이터 베이스 작업을 한 소스이다.

JDBC를 다루었던 경험이 있다면 정말 쉽게 MySQL Connector/C++ 을 이용할 수 있을 것 같다.

설명을하자면 쓸데 없는 글만 늘어 놓을 것 같으니 직접 소스를 보면 한 눈에 들어올 것이다.


    try
{
// Driver 인스턴스 가져오기
m_pDriver = sql::mysql::MySQL_Driver::Instance();

if ( m_pDriver )
{
m_pConn = m_pDriver->connect( "tcp://127.0.0.1", "root", "");

if ( m_pConn )
{
// Statement 생성
sql::Statement *pStmt = m_pConn->createStatement();
sql::ResultSet *res = NULL;

// 데이터 베이스 선택
pStmt->execute( "USE mysql" );
{
// 질의문 수행
res = pStmt->executeQuery( "SELECT host FROM user" );

// 질의결과 탐색
while( res->next() )
{
// 컬럼 데이터 가져오기
std::string host = res->getString( "host" );
TRACE( "%s\n", host.c_str() );
}

// 질의 결과 셋 해제
delete res;
}

// 데이터 베이스 생성
pStmt->execute( "CREATE DATABASE IF NOT EXISTS test" );

// 데이터 베이스 선택
pStmt->execute( "USE test" );

string strQuery;

// 테이블 스키마
strQuery = "CREATE TABLE IF NOT EXISTS member ("
" NAME CHAR(50) NOT NULL PRIMARY KEY,"
" NICK CHAR(50) NULL,"
" AGE INT NOT NULL"
")"
;

// 테이블 내용 삭제
pStmt->execute( "DELETE FROM member" );

// 테이블 생성
pStmt->execute( strQuery );
{
// Insert 문
strQuery = "INSERT INTO member ( name, nick, age )"
" VALUES ('a', 'aa', 10)";

// 레코드 삽입
pStmt->executeUpdate( strQuery );

// 삽입된 레코드 수 가져오기
int nResult = pStmt->getUpdateCount();
TRACE( "Inserted row(s): %d\n", nResult );
}

// Prepared Statement 사용하기
strQuery = "INSERT INTO member ( name, nick, age )"
" VALUES ( ?, ?, ?)";
sql::PreparedStatement *pPreStmt;
pPreStmt = m_pConn->prepareStatement( strQuery );

char name[100];

for ( int i = 0; i < 100; ++i )
{
sprintf( name, "name%03d\0", i );

// 데이터 바인딩
pPreStmt->setString( 1, name );
pPreStmt->setString( 2, "" );
pPreStmt->setInt( 3, 3 );

// Prepared Statement 수행
pPreStmt->executeUpdate();
}

// Statement 삭제
delete pStmt;
}
}
}
catch (sql::SQLException &e)
{
// 예외처리 - 에러 메시지와 에러 코드를 가져올 수 있다.
std::string err = e.what();
}




2008/12/03 - [Dev Story] - MySQL Connector/C++ 1.0.1alpha is available!
2008/12/02 - [Dev Story/Tips] - MySQL Connector/C++ 1.0.1 Alpha 컴파일 하기


Original Post : http://neodreamer-dev.tistory.com/208