mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2022, Jan de Visser <jan@de-visser.net>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/StringBuilder.h>
|
|
#include <LibSQL/Result.h>
|
|
|
|
namespace SQL {
|
|
|
|
DeprecatedString Result::error_string() const
|
|
{
|
|
VERIFY(is_error());
|
|
|
|
StringView error_code;
|
|
StringView error_description;
|
|
|
|
switch (m_error) {
|
|
#undef __ENUMERATE_SQL_ERROR
|
|
#define __ENUMERATE_SQL_ERROR(error, description) \
|
|
case SQLErrorCode::error: \
|
|
error_code = #error##sv; \
|
|
error_description = description##sv; \
|
|
break;
|
|
ENUMERATE_SQL_ERRORS(__ENUMERATE_SQL_ERROR)
|
|
#undef __ENUMERATE_SQL_ERROR
|
|
default:
|
|
VERIFY_NOT_REACHED();
|
|
}
|
|
|
|
StringBuilder builder;
|
|
builder.appendff("{}: ", error_code);
|
|
|
|
if (m_error_message.has_value()) {
|
|
if (error_description.find("{}"sv).has_value())
|
|
builder.appendff(error_description, *m_error_message);
|
|
else
|
|
builder.appendff("{}: {}", error_description, *m_error_message);
|
|
} else {
|
|
builder.append(error_description);
|
|
}
|
|
|
|
return builder.build();
|
|
}
|
|
|
|
}
|