Skip to content

Conversation

@mhoh3963
Copy link
Contributor

@mhoh3963 mhoh3963 commented Dec 11, 2025

http://jira.cubrid.org/browse/CBRD-26429

Purpose

The CSQL (CUBRID SQL Interpreter) prompt display can be modified using the user environment variable CUBRID_CSQL_PROMPT. This environment variable supports special user-defined characters (escape sequences) that the CSQL interpreter will replace with specific runtime values to build the customized prompt string.

  • The user-defined characters (escape sequences) are the follows.

    • \u or \U : replaced with the user name (currently logged in)
    • \d or \D : replaced with the database name (currently connected)
    • \h or \H : replaced with the host name (currently connected)
  • if the prompt contains multi-byte character and LANG and db codeset do not match, a warning message is output and the prompt is used "csql>".

http://jira.cubrid.org/browse/CBRD-26429

The CSQL (CUBRID SQL Interpreter) prompt display can be modified using the user environment variable CUBRID_CSQL_PROMPT.
This environment variable supports special user-defined characters (escape sequences) that the CSQL interpreter will replace with specific runtime values to build the customized prompt string.

The user-defined characters (escape sequences) are the follows.
  - /u or /U : replaced with the user name (currently logged in)
  - /d or /D : replaced with the database name (currently connected)
  - /h or /H : replaced with the host name (currently connected)
@mhoh3963 mhoh3963 self-assigned this Dec 11, 2025
@mhoh3963 mhoh3963 added this to the guava milestone Dec 11, 2025
@mhoh3963
Copy link
Contributor Author

/run all

@ctshim
Copy link
Contributor

ctshim commented Dec 11, 2025

이건 미리 질문 드려보는 것인데
장기적으로 Multi-connection을 지원하게 되면 어떻게 표시해 줘야 하나요?

@beyondykk9
Copy link
Contributor

프롬프트에 한글을 사용하는 경우, 어떻게 될까요? 경우에 따라서는 한글이 잘려서 깨질 수 있을 것 같습니다.

@mhoh3963
Copy link
Contributor Author

이건 미리 질문 드려보는 것인데 장기적으로 Multi-connection을 지원하게 되면 어떻게 표시해 줘야 하나요?

만약 csql에서 multi-connection을 지원하게 된다면, 아마도 ;switch 와 같은 command가 추가되어야 할 것 같습니다.
해당 command 수행시 prompt를 변경하면 될 것 같습니다.

@mhoh3963
Copy link
Contributor Author

프롬프트에 한글을 사용하는 경우, 어떻게 될까요? 경우에 따라서는 한글이 잘려서 깨질 수 있을 것 같습니다.
현재 버퍼의 마지막 부분처리시 한글과 같은 multi-byte 언어에 대해서는 고려하지 않아서 깨질것 같은데,
문제는 문자열안의 한글 코드가 utf8인지 ksc5601인지를 확인하기 힘들어 보입니다.

@mhoh3963
Copy link
Contributor Author

다음 사항을 추가 반영했습니다.

  • 춘택님이 코드 리뷰해준 것 반영
  • 환경변수에 \u 또는 \U 설정된 경우 call login ()에 의해 user가 변경될 경우 프롬프트가 변경되게 수정
  • 프롬프트의 마지막 문자열이 공백이 아닌 경우 무조건 공백 문자를 넣게 수정

@mhoh3963
Copy link
Contributor Author

/run all

@mhoh3963
Copy link
Contributor Author

/run all

@mhoh3963
Copy link
Contributor Author

LC_ALL 과 LANG 설정 없이 CUBRID_CSQL_PROMPT에 한글 utf8 사용시 csql의 readline() 함수에 segfault를 발생하는데,
ascii 코드만 지원해야 할 것 같은데, 의견부탁드립니다.

@ctshim
Copy link
Contributor

ctshim commented Dec 15, 2025

LC_ALL 과 LANG 설정 없이 CUBRID_CSQL_PROMPT에 한글 utf8 사용시 csql의 readline() 함수에 segfault를 발생하는데,
ascii 코드만 지원해야 할 것 같은데, 의견부탁드립니다.

ascii만 지원하자는 것에 찬성합니다.
다만, 사용자가 한글을 썼을 때 체크해서 에러를 낼 것인지요? 아니면 무시?

- modify to add "> " to prompt string
- fix segfault when trying to login with non-existent user using ;connect
@mhoh3963
Copy link
Contributor Author

/run all

@mhoh3963
Copy link
Contributor Author

/run all

@beyondykk9
Copy link
Contributor

LC_ALL 과 LANG 설정 없이 CUBRID_CSQL_PROMPT에 한글 utf8 사용시 csql의 readline() 함수에 segfault를 발생하는데,
ascii 코드만 지원해야 할 것 같은데, 의견부탁드립니다.

ascii만 지원하자는 것에 찬성합니다. 다만, 사용자가 한글을 썼을 때 체크해서 에러를 낼 것인지요? 아니면 무시?

한글로 만들어진 유저가 있다면 어떻게 처리가 될까요?
예를 들면 create user "홍길동"으로 만들어진 "홍길동"이라는 유저가 있다면, /U를 사용했을 때, "홍길동" 표시가 아예 나타나지 않을 것 같네요.

@mhoh3963
Copy link
Contributor Author

mhoh3963 commented Dec 16, 2025

LC_ALL 과 LANG 설정 없이 CUBRID_CSQL_PROMPT에 한글 utf8 사용시 csql의 readline() 함수에 segfault를 발생하는데,
ascii 코드만 지원해야 할 것 같은데, 의견부탁드립니다.

ascii만 지원하자는 것에 찬성합니다. 다만, 사용자가 한글을 썼을 때 체크해서 에러를 낼 것인지요? 아니면 무시?

한글로 만들어진 유저가 있다면 어떻게 처리가 될까요? 예를 들면 create user "홍길동"으로 만들어진 "홍길동"이라는 유저가 있다면, /U를 사용했을 때, "홍길동" 표시가 아예 나타나지 않을 것 같네요.

대체되는 문자열에 대해서는 ignore code가 없어서, LC_ALL 과 LANG 설정이 없으면 segfault가 발생합니다.

@beyondykk9
Copy link
Contributor

LC_ALL 과 LANG 설정 없이 CUBRID_CSQL_PROMPT에 한글 utf8 사용시 csql의 readline() 함수에 segfault를 발생하는데,
ascii 코드만 지원해야 할 것 같은데, 의견부탁드립니다.

ascii만 지원하자는 것에 찬성합니다. 다만, 사용자가 한글을 썼을 때 체크해서 에러를 낼 것인지요? 아니면 무시?

한글로 만들어진 유저가 있다면 어떻게 처리가 될까요? 예를 들면 create user "홍길동"으로 만들어진 "홍길동"이라는 유저가 있다면, /U를 사용했을 때, "홍길동" 표시가 아예 나타나지 않을 것 같네요.

대체되는 문자열에 대해서는 ignore code가 없어서, LC_ALL 과 LANG 설정이 없으면 segfault가 발생합니다.

LC_ALL과 LANG 설정이 없으면, 설정을 ko_KR.utf8로 해주면 어떨까요? 그럼, 한글 문제도 해결이 될 것 같습니다.

@beyondykk9
Copy link
Contributor

beyondykk9 commented Dec 19, 2025

PR 설명 부분에 환경 변수 옵션을 "/"로 표시하고 있는데, "\"로 수정되어야 합니다.
그리고 한글 관련해서, LC_ALL과 LANG 환경 변수 설정이 안 되어 있는 경우, 사용자가 설정할 수 있도록 가이드 메시지를 출력한 후 종료하는 게 어떨지요.

@mhoh3963
Copy link
Contributor Author

PR 설명 부분에 환경 변수 옵션을 "/"로 표시하고 있는데, ""로 수정되어야 합니다. 그리고 한글 관련해서, LC_ALL과 LANG 환경 변수 설정이 안 되어 있는 경우, 사용자가 설정할 수 있도록 가이드 메시지를 출력한 후 종료하는 게 어떨지요.

PR 살명은 수정했습니다.
change_prompt()에서 multi-byte인 경우 LANG 환경변수가 없는 경우 LANG 설정하라는 메세지를 출력하고 오류를 발생하게 수정해봤는데, 문제는 LANG 환경 변수에 설정을 잘 못한 경우에는 동일하게 segfault 가 발생하네요.
libedit에서 segfault 발생하는 것을 수정해야 할 것 같네요.

@beyondykk9
Copy link
Contributor

PR 설명 부분에 환경 변수 옵션을 "/"로 표시하고 있는데, ""로 수정되어야 합니다. 그리고 한글 관련해서, LC_ALL과 LANG 환경 변수 설정이 안 되어 있는 경우, 사용자가 설정할 수 있도록 가이드 메시지를 출력한 후 종료하는 게 어떨지요.

PR 살명은 수정했습니다. change_prompt()에서 multi-byte인 경우 LANG 환경변수가 없는 경우 LANG 설정하라는 메세지를 출력하고 오류를 발생하게 수정해봤는데, 문제는 LANG 환경 변수에 설정을 잘 못한 경우에는 동일하게 segfault 가 발생하네요. libedit에서 segfault 발생하는 것을 수정해야 할 것 같네요.

LC_ALL과 LANG에 설정할 수 있는 내용을 iso88591, utf8, euckr로 한정하고 나머지는 모두 에러 처리하면 어떨지요?

@mhoh3963
Copy link
Contributor Author

PR 설명 부분에 환경 변수 옵션을 "/"로 표시하고 있는데, ""로 수정되어야 합니다. 그리고 한글 관련해서, LC_ALL과 LANG 환경 변수 설정이 안 되어 있는 경우, 사용자가 설정할 수 있도록 가이드 메시지를 출력한 후 종료하는 게 어떨지요.

PR 살명은 수정했습니다. change_prompt()에서 multi-byte인 경우 LANG 환경변수가 없는 경우 LANG 설정하라는 메세지를 출력하고 오류를 발생하게 수정해봤는데, 문제는 LANG 환경 변수에 설정을 잘 못한 경우에는 동일하게 segfault 가 발생하네요. libedit에서 segfault 발생하는 것을 수정해야 할 것 같네요.

LC_ALL과 LANG에 설정할 수 있는 내용을 iso88591, utf8, euckr로 한정하고 나머지는 모두 에러 처리하면 어떨지요?

현재 사용중인 libedit에서 core 나는 부분은 수정할 예정입니다.
change_prompt() 에서 multi-byte인 경우에는 현재 DB의 codeset과 설정된 locale 를 비교해서 다른 경우에는 오류를 발생하게 할 예정입니다. (db codeset이 utf8, euckr 인 경우에만 LANG 설정 이후 multi-byte를 prompt에서 사용할 수 있게할 예정입니다.)

… do not match, a warning message is output and the prompt is changed to use "csql>".
@mhoh3963 mhoh3963 requested a review from ctshim December 23, 2025 00:50
set(WITH_LIBEXPAT_URL "https://github.com/CUBRID/3rdparty/raw/develop/expat/expat-2.6.4.tar.gz") # expat library sources URL
set(WITH_LIBJANSSON_URL "https://github.com/CUBRID/3rdparty/raw/develop/jansson/jansson-2.10.tar.gz") # jansson library sources URL
set(WITH_LIBEDIT_URL "https://github.com/CUBRID/libedit/archive/refs/tags/csql_v1.1.tar.gz") # editline library sources URL
set(WITH_LIBEDIT_URL "https://github.com/CUBRID/libedit/archive/refs/tags/csql_v1.2.tar.gz") # editline library sources URL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LANG 설정이 안되어 있고, prompt에 멀티바이트 사용하여 readline 호출시 core 발생하는 것을 수정해서 머지해두었습니다.

}

#if !defined (WINDOW)
/* check if the prompt contains multi-byte characters */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prompt에 multi-byte 문자가 있는지 확인 후 있는 경우 db codeset를 얻어서 OS에서 설정한 locale과 확인하는 코드 추가하였음. (db codeset가 iso88591 인경우에는 무조건 경고)
만약 OS의 locale이 다를 경우 경고 메세지를 출력후, "csql>"로 프롬프트 변경하게 수정함.

@mhoh3963
Copy link
Contributor Author

/run all

}

/* veify if match LANG and DB codeset */
if (strcasestr (locale, find1) || strcasestr (locale, find2))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (strcasestr (locale, find1) == 0 || strcasestr (locale, find2) == 0)
이렇게 체크해야 하지 않을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strcasestr() 은 찾는 경우에는 포인터를 넘겨주고, 찾는 못하는 경우에는 NULL을 반환하게 되어 있습니다.
find1 또는 find2가 locale에 있으면 정상적인 경우로 판단하고 있습니다.

아래처럼 명시적으로 변경해야 할까요 ?
if ((strcasestr (locale, find1) != NULL || strcasestr (locale, find2) != NULL)

@mhoh3963
Copy link
Contributor Author

/run sql

@mhoh3963
Copy link
Contributor Author

/run all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants