GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • Sign up
  • Explore
  • Enterprise
  • Education
  • Search
  • Help
  • Terms of use
  • About Us
  • Gitee Premium
  • Gitee AI
  • AI teammates

This view

  • Original page
  • New address

GeezerVison is showing gitee.com — components/example/test_string_service_charset.cc · 万里数据库/GreatSQL - Gitee

Fetch the repository succeeded.
Open Source > Database Related > Database Service &&
richgiteeai
Watch
Unwatch Watching Releases Only Ignoring
75
Star 800 Fork 122

GVP万里数据库 / GreatSQL

Code Issues 5 Pull Requests 0 Wiki Insights Pipelines
Service
Sonar mini
Quality Analysis
Jenkins for gitee
Jenkins for Gitee
Cloudbase
Tencent CloudBase
Cloud serverless
Tencent Cloud Serverless
Logo
悬镜安全
Sae
Aliyun SAE
Codeblitz
Codeblitz
Sbom
SBOM
Qilin profile
DevLens
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (11)
Tags (12)
Manage
Manage
master
greatsql-8.4.4-5
greatsql-8.4.4-4
greatsql-8.0.32-27
greatsql-8.0.32-25
greatsql-8.0.32-26
greatsql-8.0.32-24
greatsql-8.0.25-17
greatsql-8.0.25-16
greatsql-8.0.25-15
greatsql-5.7.36-39
GreatSQL-8.4.4-5
V8.4.4-5
GreatSQL-8.4.4-4
GreatSQL-8.4.4
GreatSQL-8.0.32-27
GreatSQL-8.0.32-26
GreatSQL-8.0.32-25
GreatSQL-8.0.32-24
GreatSQL-8.0.25-17
GreatSQL-8.0.25-16
GreatSQL-5.7.36-39
GreatSQL-8.0.25-15
master
Branches (11)
Tags (12)
Manage
Manage
master
greatsql-8.4.4-5
greatsql-8.4.4-4
greatsql-8.0.32-27
greatsql-8.0.32-25
greatsql-8.0.32-26
greatsql-8.0.32-24
greatsql-8.0.25-17
greatsql-8.0.25-16
greatsql-8.0.25-15
greatsql-5.7.36-39
GreatSQL-8.4.4-5
V8.4.4-5
GreatSQL-8.4.4-4
GreatSQL-8.4.4
GreatSQL-8.0.32-27
GreatSQL-8.0.32-26
GreatSQL-8.0.32-25
GreatSQL-8.0.32-24
GreatSQL-8.0.25-17
GreatSQL-8.0.25-16
GreatSQL-5.7.36-39
GreatSQL-8.0.25-15
Clone or Download
Clone/Download
HTTPS SSH SVN SVN+SSH Download ZIP
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://[email protected]': # Private Token
master
Branches (11)
Tags (12)
Manage
Manage
master
greatsql-8.4.4-5
greatsql-8.4.4-4
greatsql-8.0.32-27
greatsql-8.0.32-25
greatsql-8.0.32-26
greatsql-8.0.32-24
greatsql-8.0.25-17
greatsql-8.0.25-16
greatsql-8.0.25-15
greatsql-5.7.36-39
GreatSQL-8.4.4-5
V8.4.4-5
GreatSQL-8.4.4-4
GreatSQL-8.4.4
GreatSQL-8.0.32-27
GreatSQL-8.0.32-26
GreatSQL-8.0.32-25
GreatSQL-8.0.32-24
GreatSQL-8.0.25-17
GreatSQL-8.0.25-16
GreatSQL-5.7.36-39
GreatSQL-8.0.25-15
GreatSQL
/
components
/
example
/
test_string_service_charset.cc
Branches 11
Tags 12
GreatSQL
/
components
/
example
/
test_string_service_charset.cc
test_string_service_charset.cc 9.86 KB
Copy Edit Raw Blame History
GreatSQL authored 2026-06-30 12:09 +08:00 . GreatSQL 8.4.4-5 GA(2026-06-30)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
/* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include <fcntl.h>
#include <mysql/components/component_implementation.h>
#include <mysql/components/service_implementation.h>
#include <mysql/components/services/mysql_string.h>
#include <stdio.h>
#include "m_string.h" // strlen
#include "my_inttypes.h"
#include "my_sys.h" // my_write, my_malloc
#include "sql_string.h"
#include "test_string_service_long.h" // same header
FILE *outfile;
// Value must be a multiple of 16 (or TEST_TEXT_LIT_LENGTH)
#define MAX_BUFFER_LENGTH 128
int log_text_len = 0;
char log_text[MAX_BUFFER_LENGTH + 16];
// strcpy (log_text, lit_log_text);
#define WRITE_LOG(format, lit_log_text) \
log_text_len = sprintf(log_text, format, lit_log_text); \
if (fwrite((uchar *)log_text, sizeof(char), log_text_len, outfile) != \
static_cast<size_t>(log_text_len)) \
return true;
/**
This file contains a test (example) component, which tests the service
"string".
*/
bool test_charset(const char *charset, const char *text, int buff_len) {
WRITE_LOG("%s\n",
"-------------------------------------------------------------");
WRITE_LOG("Charset: %s\n", charset);
WRITE_LOG("%s\n", text);
my_h_string out_string = nullptr;
char low_test_text[MAX_BUFFER_LENGTH];
char upper_test_text[MAX_BUFFER_LENGTH];
if (mysql_service_mysql_string_factory->create(&out_string)) {
WRITE_LOG("%s\n", "Create string failed.");
} else {
mysql_service_mysql_string_factory->destroy(out_string);
WRITE_LOG("%s\n", "Destroy string object.");
// Valid convert from buffer
if (mysql_service_mysql_string_converter->convert_from_buffer(
&out_string,
text, // its a input buffer
buff_len, charset)) {
WRITE_LOG("%s\n", "Convert from buffer failed.");
} else {
uint out_length = 0;
WRITE_LOG("%s\n", "Convert from buffer passed.");
// valid get number of chars
if (mysql_service_mysql_string_character_access->get_char_length(
out_string, &out_length)) {
WRITE_LOG("%s\n", "Get number of chars failed.");
} else {
WRITE_LOG("Number of chars: %d\n", out_length);
}
out_length = 0;
// valid get number of bytes
if (mysql_service_mysql_string_byte_access->get_byte_length(
out_string, &out_length)) {
WRITE_LOG("%s\n", "Get number of bytes failed.");
} else {
WRITE_LOG("Number of bytes: %d\n", out_length);
}
// Convert to low string
my_h_string low_string = nullptr;
if (mysql_service_mysql_string_factory->create(&low_string)) {
WRITE_LOG("%s\n", "Create lower string object failed.");
} else {
if (mysql_service_mysql_string_case->tolower(&low_string, out_string)) {
WRITE_LOG("%s\n", "Tolower failed.");
} else {
WRITE_LOG("%s\n", "Tolower passed:");
// Convert low string to buffer
if (mysql_service_mysql_string_converter->convert_to_buffer(
low_string, low_test_text, MAX_BUFFER_LENGTH, charset)) {
WRITE_LOG("%s\n", "Convert to buffer failed.");
} else {
WRITE_LOG("%s\n", low_test_text);
}
}
}
mysql_service_mysql_string_factory->destroy(low_string);
// Convert to upper string
my_h_string upper_string = nullptr;
if (mysql_service_mysql_string_factory->create(&upper_string)) {
WRITE_LOG("%s\n", "Create upper string object failed.");
} else {
if (mysql_service_mysql_string_case->toupper(&upper_string,
out_string)) {
WRITE_LOG("%s\n", "Toupper failed.");
} else {
WRITE_LOG("%s\n", "Toupper passed:");
if (mysql_service_mysql_string_converter->convert_to_buffer(
upper_string, upper_test_text, MAX_BUFFER_LENGTH, charset)) {
WRITE_LOG("%s\n", "Convert to buffer failed.");
} else {
WRITE_LOG("%s\n", upper_test_text);
}
}
}
mysql_service_mysql_string_factory->destroy(upper_string);
// Get char with index 1
ulong out_char;
if (mysql_service_mysql_string_character_access->get_char(out_string, 1,
&out_char)) {
WRITE_LOG("%s\n", "Get char with index 1 failed.");
} else {
WRITE_LOG("%s\n", "Get char with index 1 passed.");
}
// Get char with index > strlen : Must fail
if (mysql_service_mysql_string_character_access->get_char(
out_string, strlen(text) + 1, &out_char)) {
WRITE_LOG("%s\n", "Get char with index > strlen passed.");
}
// Get byte with index strlen
uint out_byte;
if (mysql_service_mysql_string_byte_access->get_byte(
out_string, strlen(text) - 1, &out_byte)) {
WRITE_LOG("%s\n", "Get byte with index strlen failed.");
} else {
WRITE_LOG("%s\n", "Get byte with index strlen passed.");
}
}
}
mysql_service_mysql_string_factory->destroy(out_string);
WRITE_LOG("%s\n", "Destroy string object.");
return false;
}
/**
@brief tests for a memory leak on an invalid chaset
@retval true failure
@return false success
*/
static bool test_invalid_charset() {
my_h_string out_string = nullptr;
WRITE_LOG("%s\n", "Test invalid chaset: should fail but not leak");
if (mysql_service_mysql_string_converter->convert_from_buffer(
&out_string,
"haha", // its a input buffer
4, "invalid charset")) {
WRITE_LOG("%s\n", "Convert from buffer failed.");
}
return out_string != nullptr;
}
/**
Initialization entry method for test component.
It executes the tests of the service.
*/
mysql_service_status_t test_string_service_init() {
const char *chs_latin1 = "latin1";
const char *chs_utf8mb3 = "utf8mb3";
const char *chs_gb18030 = "gb18030";
// const char* charset="utf8mb4";
#define TEST_TEXT_LIT_LENGTH 48
const char *test_text_eng =
"Greetings from beautiful Austria at March, 9th!"; // 48 chars
const char *test_text_ger =
"Grüße aus dem schönen Österreich am 9. März!"; // 48 chars
const char *test_text_chinese = "遥想公瑾当年,小乔初嫁了,雄姿英发";
bool retcode = false;
const char *filename = "test_string_service_charset.log";
unlink(filename);
outfile = fopen(filename, "w+");
WRITE_LOG("%s\n", "test_string_service_long init:");
retcode = test_charset(chs_latin1, test_text_eng, TEST_TEXT_LIT_LENGTH);
retcode |= test_charset(chs_latin1, test_text_ger, TEST_TEXT_LIT_LENGTH);
retcode |= test_charset(chs_utf8mb3, test_text_eng, TEST_TEXT_LIT_LENGTH);
retcode |= test_charset(chs_utf8mb3, test_text_ger, TEST_TEXT_LIT_LENGTH);
retcode |= test_charset(chs_utf8mb3, test_text_chinese, TEST_TEXT_LIT_LENGTH);
retcode |= test_charset(chs_gb18030, test_text_chinese, TEST_TEXT_LIT_LENGTH);
retcode |= test_invalid_charset();
WRITE_LOG("%s\n", "End of init");
fclose(outfile);
return retcode;
}
/**
De-initialization method for Component.
*/
mysql_service_status_t test_string_service_deinit() { return false; }
/* An empty list as no service is provided. */
BEGIN_COMPONENT_PROVIDES(test_string_service_charset)
END_COMPONENT_PROVIDES();
REQUIRES_SERVICE_PLACEHOLDER(mysql_string_factory);
REQUIRES_SERVICE_PLACEHOLDER(mysql_string_converter);
REQUIRES_SERVICE_PLACEHOLDER(mysql_string_character_access);
REQUIRES_SERVICE_PLACEHOLDER(mysql_string_byte_access);
REQUIRES_SERVICE_PLACEHOLDER(mysql_string_case);
REQUIRES_SERVICE_PLACEHOLDER(mysql_string_iterator);
REQUIRES_SERVICE_PLACEHOLDER(mysql_string_ctype);
/* A list of required services. */
BEGIN_COMPONENT_REQUIRES(test_string_service_charset)
REQUIRES_SERVICE(mysql_string_factory),
REQUIRES_SERVICE(mysql_string_converter),
REQUIRES_SERVICE(mysql_string_character_access),
REQUIRES_SERVICE(mysql_string_byte_access),
REQUIRES_SERVICE(mysql_string_case),
REQUIRES_SERVICE(mysql_string_iterator),
REQUIRES_SERVICE(mysql_string_ctype), END_COMPONENT_REQUIRES();
/* A list of metadata to describe the Component. */
BEGIN_COMPONENT_METADATA(test_string_service_charset)
METADATA("mysql.author", "Oracle Corporation"),
METADATA("mysql.license", "GPL"),
METADATA("test_string_charset_service", "1"), END_COMPONENT_METADATA();
/* Declaration of the Component. */
DECLARE_COMPONENT(test_string_service_charset,
"mysql:test_string_service_charset")
test_string_service_init, test_string_service_deinit END_DECLARE_COMPONENT();
/* Defines list of Components contained in this library. Note that for now
we assume that library will have exactly one Component. */
DECLARE_LIBRARY_COMPONENTS &COMPONENT_REF(test_string_service_charset)
END_DECLARE_LIBRARY_COMPONENTS
Loading...
Go
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Type
Please select a report type
Reason
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

GreatSQL是一款开源免费数据库,可在普通硬件上满足金融级应用场景,具有高可用、高性能、高兼容、高安全等特性,可作为MySQL或Percona Server for MySQL的理想可选替换。 expand collapse
数据库
No labels
https://greatsql.cn/
unknown license
unknown open source license
800 Stars
75 Watching
122 Forks
Cancel

Releases (10)

All
GreatSQL 8.4.4-5

The Open Source Evaluation Index is derived from the OSS Compass evaluation system, which evaluates projects around the following three dimensions

1. Open source ecosystem

  • Productivity: To evaluate the ability of open-source projects to output software artifacts and open-source value.
  • Innovation: Used to evaluate the degree of diversity of open source software and its ecosystem.
  • Robustness: Used to evaluate the ability of open-source projects to resist internal and external interference and self recover in the face of changing development environments.

2. Collaboration, People, Software

  • Collaboration: represents the degree and depth of collaboration in open source development behavior.
  • Observe the influence of core personnel in open source projects, and examine the evaluations of users and developers on open source projects from a third-party perspective.
  • Software: Evaluate the value of products exported from open-source projects and their ultimate destination. It is also a concrete manifestation of "open source software", one of the oldest mainstream directions in open source evaluation.

3. Evaluation model

    Based on the dimensions of "open source ecosystem" and "collaboration, people, and software", identify quantifiable indicators directly or indirectly related to this goal, quantitatively evaluate the health and ecology of open source projects, and ultimately form an open source evaluation index.

Contributors

All

Language(Optional)

C++ 72.4% C 18.3% PHP 2.0% Java 1.7% Makefile 1.1% Other 4.5%

Activities

Load More
can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/GreatSQL/GreatSQL.git
[email protected]:GreatSQL/GreatSQL.git
GreatSQL
GreatSQL
GreatSQL
master
Going to Help Center

Search

Git 命令在线学习 如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.