2015년 8월 31일 월요일

Oracle(OCI Library) Error 처리

Oracle(OCI Library) Error 처리



1. 에러핸들러(Error handler) 이용


#include "ocilib.h"

void err_handler(OCI_Error *err)
{
  printf("code  : ORA-%05i\n"
         "msg   : %s\n"
         "sql   : %s\n",
         OCI_ErrorGetOCICode(err), 
         OCI_ErrorGetString(err),
         OCI_GetSql(OCI_ErrorGetStatement(err)));
}
  
int main()
{
  OCI_Connection *cn;
  
  if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;
  
  cn = OCI_ConnectionCreate("wrong_db", "wrong_usr", "wrong_pwd", 
                            OCI_SESSION_DEFAULT);
  
  /* ... application code here ... */
  
  OCI_Cleanup();
  
  return EXIT_SUCCESS;
}



2. 함수(Function)에서 에러 출력


#include "ocilib.h"
  
int main()
{
  OCI_Connection *cn;
  
  if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_CONTEXT))
    return EXIT_FAILURE;
  
  cn = OCI_ConnectionCreate("wrong_db", "wrong_usr", "wrong_pwd", OCI_SESSION_DEFAULT);
  
  if (cn == NULL)
  {
     OCI_Error *err = OCI_GetLastError();
     printf("errcode %d, errmsg %s", OCI_ErrorGetOCICode(err),  OCI_ErrorGetString(err));
  }
  
  OCI_Cleanup();
  
  return EXIT_SUCCESS;
}


자세한 내용은 여기로.

2015년 8월 24일 월요일

[명언] 톨스토이

깊은 강물은 돌을 집어던져도 흐려지지 않는다.
모욕을 받고 그 즉시 화를 내는 사람은 작은 웅덩이에 불과하다.
- 톨스토이

오라클 캐릭터셋 확인


----------------------------------------------------------------------
--오라클 캐릭터셋 확인
Select *
From nls_database_parameters
Where parameter='NLS_CHARACTERSET' Or parameter='NLS_LANGUAGE'
----------------------------------------------------------------------


2015년 8월 20일 목요일

[용어] URI, URL, URN

출처 아직도 가야 할 길 (The Road Less Traveled) | 우보
원문 http://blog.naver.com/wikiware/100019145703


URI(Uniform Resource Identifier)는 어떤 구문을 가진 문자열로 구성된 인터넷 프로토콜 요소이다. 이 문자열은 리소스를 참조하는데 사용되는 이름 또는 주소로 구성된다. URI는 위치이거나 이름이거나 이 둘 다가 될 수 있다. 한마디로 URIURL이거나 URN이거나 동시에 URLURL이 될 수 있다.



URL(Uniform Resource Locator)은 네트웍 주소나 리소스에 접근하기 위한 메카니즘을 기술함으로써 리소스를 얻거나 리소스에 어떤 동작을 취하기 위한 수단을 제공하는 URI이다. 예를 들면, http://www.naver.com/는 리소스를 가르키는 URI이며, 이 리소스를 네크웍으로부터 얻기 위해서는 www.naver.com이라는 호스트로부터 HTTP 프로토콜을 통해서 얻을 수 있다는 것을 나타내는 URI이다. URL로 사용되는 스킴스키마(scheme)은 http, https, ftp, mailto, idap, file, news, gopher, telnet 등이 있다.



URN(Uniform Resource Name)은 특정 네임 공간에서 이름에 의해 리소스를 식별하는 URI이다. URN은 리소스의 위치나 리소스 습득 방법을 명시하지 않고 단지 그 리소스에 대해서만 말하는데 사용될 수 있다. 예를 들면, urn:ISBN:1-234-5678-9라는 URN은 ISBN(International StandardBook Number)와 같이 책 번호에 대해서만 말을 하고 있지, 어디서 어떻게 이 책을 구할 수 있는지는 명시하지 않는다. URN은 urn 스킴을스키마를 사용한 URI이다.



URLURNURI를 문맥 의존적 관점에서 본 것이다. URLURNURI의 부분 집합이다. URI의 구문은 "URI 스킴스키마"(보통 http, ftp, mailto, urn과 같은 프로토콜) + "콜론"(:) + "구체적인 스킴스키마"으로 구성된다. 구체적인 스킴스키마의 구문과 의미는 각 스킴스키마에 따라서 규정된다. http 스킴스키마의 경우 //adress/path?query 형식을 갖는다. address는 호스트 이름이거나 IP 주소이고, 때에 따라서는 이 후에 콜론을 쓰고 포트 번호를 쓰기도 한다. path는 계층 구조를 가진 절대 경로이거나 상대 경로가 될 수 있다. 다음은 URI의 예이다.

http://somehost/absolute/URI/with/absolute/path/to/resource.txt
ftp://somehost/resource.txt
urn:issn:1535-3613
http://example/resource.txt#frag01



위 예에서, http://somehost/absolute/URI/with/absolute/path/to/resource.txt 는 http 스킴을스키마를 사용하여 URL을 기술한 URI이며, ftp://somehost/resource.txt는 ftp 스킴을스키마를 사용한 URL이며, urn:issn:1535-3613는 URN 스킴을스키마를 사용한 URN이다. http://example/resource.txt#frag01는 http 스킴을스키마를 사용한 URL 참조의 예이다.







What is Unicode?

What is Unicode?

Unicode provides a unique number for every character,
no matter what the platform,
no matter what the program,
no matter what the language.
   Unicode Book Cover
Fundamentally, computers just deal with numbers. They store letters and other characters by assigning a number for each one. Before Unicode was invented, there were hundreds of different encoding systems for assigning these numbers. No single encoding could contain enough characters: for example, the European Union alone requires several different encodings to cover all its languages. Even for a single language like English no single encoding was adequate for all the letters, punctuation, and technical symbols in common use.
These encoding systems also conflict with one another. That is, two encodings can use the same number for two different characters, or use different numbers for the same character. Any given computer (especially servers) needs to support many different encodings; yet whenever data is passed between different encodings or platforms, that data always runs the risk of corruption.

Unicode is changing all that!

Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language. The Unicode Standard has been adopted by such industry leaders as Apple, HP, IBM, JustSystems, Microsoft, Oracle, SAP, Sun, Sybase, Unisys and many others. Unicode is required by modern standards such as XML, Java, ECMAScript (JavaScript), LDAP, CORBA 3.0, WML, etc., and is the official way to implement ISO/IEC 10646. It is supported in many operating systems, all modern browsers, and many other products. The emergence of the Unicode Standard, and the availability of tools supporting it, are among the most significant recent global software technology trends.
Incorporating Unicode into client-server or multi-tiered applications and websites offers significant cost savings over the use of legacy character sets. Unicode enables a single software product or a single website to be targeted across multiple platforms, languages and countries without re-engineering. It allows data to be transported through many different systems without corruption.

About the Unicode Consortium

The Unicode Consortium was founded to develop, extend and promote use of the Unicode Standard, which specifies the representation of text in modern software products and standards. The Consortium is a non-profit, 501(c)(3) charitable organization. The membership of the Consortium represents a broad spectrum of corporations and organizations in the computer and information processing industry. The Consortium is supported financially through membership dues and donations. Membership in the Unicode Consortium is open to organizations and individuals anywhere in the world who support the Unicode Standard and wish to assist in its extension and implementation. All are invited to contribute to the support of the Consortium's important work by making a donation.
For more information, see the GlossaryTechnical Introduction and Useful Resources.







2015년 8월 4일 화요일

C에서 MySQL연결 시 한글(UTF-8)깨짐문제 해결

mysql_init(&mysql);
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "utf8");
mysql_options(&mysql, MYSQL_INIT_COMMAND, "SET NAMES utf8");
mysql_real_connect(&mysql,T_SERVER, T_USER, T_PASSWD, T_DBNM,0,0,0);






연암 박지원

우리 형님 얼굴 수염 누구를 닮았던가
『我兄顔髮曾誰似』

돌아가신 아버님 그리울 때마다 우리 형님 쳐다봤지
『每憶先君看我兄』

이제 형님 그리우면 어디에서 본단 말고
『今日思兄何處見』

두건 쓰고 도포 입고 나가 냇물에 비친 나를 보아야겠네
『自將巾袂映溪行』

— 연암(燕巖) 박지원(朴趾源, 1737~1805년)






코야마키요시 “이삭줍기” 中..


“어떠한 도움이 되지 않는다 하여도
우리가 서로에게 필요한 사이가 된다면
얼마나 좋을까..”

— 코야마키요시 “이삭줍기” 中
小山淸の「落穂拾ひ: 聖アンデルセン」







쓸모없는 짓에 최선을 다하는 것



아버지가 그랬다,
시란 쓸모없는 짓이라고.


어느날 아버지가 다시 말했다,
기왕이면 시작했으니최선을 다해보라고.


쓸모없는 짓에 최선을 다하는 것,
이게 나의 슬픔이고 나를 버티게 한 힘이다.”




— 손택수 시집『목련전차』중 ‘시인의 말’







보수적인 사람이 되는 이유


사람은 나이가 들면 신중해진다. 
한쪽 이야기만 듣고 판단했다가 큰 코 다칠 수 있다는 사실을 경험으로 얻었기 때문이다. 
따라서 어떠한 상황 변화에 빠르게 대처하지 못하고 '일단 두고보자'는 입지를 고수한다.

'보수'는 이러한 신중함에 기인한다.


— 이호윤




기억이란..



기억나지 않는다고 해서
무의미한 것은 아니야.
눈을 감아도 세상이
사라지지 않는 것 처럼.


—  《영화"메멘토"중에서》




2015년 8월 3일 월요일

C의 오버로딩?! → 이런 지원도 있었나.. 하지만 gcc는 안되는걸.. ≪ _Generic() ≫


#define myfunction(X) _Generic((X), long double:myfunction_longdouble, default:myfunction_double, float:myfunction_float )(X)

"최근에 정의된 C 표준 C11에서는 _Generic()이라는 키워드를 도입해서 컴파일 시점에 이런 기능을 편하게 정의할 수 있도록 하였다. 앞의 코드는 다음과 같이 C 스타일로 변경해서 사용할 수 있다.  ...

(中略)

참고로 이 기능은 C11에서 소개되었기 때문에 이 표준을 따르지 않는 컴파일러에 서는 지원하지 않는다. 실제로 gcc에서 이 코드를 컴파일하면 다음과 같은 에러 메 시지를 출력한다."

- [리얼타임] 프로그래머가 몰랐던 프로그램의 동작 원리(프로그램 개발편) 中..


내용출처: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_13.1.2/com.ibm.xlc131.aix.doc/language_ref/genericselection.html

포럼참고: http://stackoverflow.com/questions/9864513/gcc-allow-overloaded-functions-in-c99

Generic selection (C11)

A generic selection is a primary expression. Its type and value depend on the selected generic association.
The following diagram shows the generic selection syntax:
Read syntax diagramSkip visual syntax diagram
                                          .-,-----------------------------------------.      
                                          V                                           |      
>>-_Generic--(--assignment-expression--,----+-type-name--:--assignment-expression---+-+--)-><
                                            |                                   (1) |        
                                            '-default--:--assignment-expression-----'        


Notes:
  1. A generic selection can have at most one default generic association.
where:
type-name
Specifies the type of a generic association. The type name that you specify in a generic association must be a complete object type other than a variably modified type.
assignment-expression
Is an assignment expression. The first assignment expression is called the controlling expression.
The generic association list is a group of generic associations. There are two forms of generic associations:
  • type-name: assignment-expression
  • default: assignment-expression
One generic selection cannot have two or more generic associations that specify compatible types. In one generic selection, the controlling expression can have at most one compatible type name in the generic association list. If a generic selection has no default generic association, its controlling expression must have exactly one compatible type name in its generic association list.
If there is a generic association with a type name that is compatible with the controlling expression in the generic selection, the expression in the generic selection is the result expression. Otherwise, the result expression of the generic selection is the expression in the default generic association. The controlling expression of a generic selection is not evaluated. None of the expressions from any other generic association of the generic selection is evaluated.
The type and value of a generic selection are identical to those of its result expression. For example, a generic selection is an lvalue, a function designator, or a void expression if its result expression is an lvalue, a function designator, or a void expression.

Example

The following sample myprogram.c defines a type-generic macro:
#define myfunction(X) _Generic((X), \
long double:myfunction_longdouble, \
default:myfunction_double, \
float:myfunction_float \
)(X)
void myfunction_longdouble(long double x){printf("calling %s\n",__func__);}
void myfunction_double(double x){printf("calling %s\n",__func__);} 
void myfunction_float(float x){printf("calling %s\n",__func__);}

int main()
{
  long double ld;
  double d;
  float f;
  myfunction(ld);
  myfunction(d);
  myfunction(f);
} 
When you execute the program:
xlc myprogram.c -qldbl128 -qlanglvl=extc1x
./a.out
the result is as follows:
calling myfunction_longdouble
calling myfunction_double
calling myfunction_float