Compare commits
2 Commits
342743bf5a
...
be6acf3e0e
Author | SHA1 | Date | |
---|---|---|---|
be6acf3e0e | |||
f1b0f33ec4 |
192
.clang-format
Normal file
192
.clang-format
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: None
|
||||||
|
AlignConsecutiveMacros: None
|
||||||
|
AlignConsecutiveAssignments: None
|
||||||
|
AlignConsecutiveBitFields: None
|
||||||
|
AlignConsecutiveDeclarations: None
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
|
AttributeMacros:
|
||||||
|
- __capability
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeConceptDeclarations: true
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 140
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
QualifierAlignment: Leave
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DeriveLineEnding: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
PackConstructorInitializers: BinPack
|
||||||
|
BasedOnStyle: ''
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IfMacros:
|
||||||
|
- KJ_IF_MAYBE
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||||
|
Priority: 3
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 1
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentRequires: false
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
InsertTrailingCommas: None
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakOpenParenthesis: 0
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
|
PointerAlignment: Right
|
||||||
|
PPIndentWidth: -1
|
||||||
|
ReferenceAlignment: Pointer
|
||||||
|
ReflowComments: true
|
||||||
|
RemoveBracesLLVM: false
|
||||||
|
SeparateDefinitionBlocks: Leave
|
||||||
|
ShortNamespaceLines: 1
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
SortJavaStaticImport: Before
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: true
|
||||||
|
AfterForeachMacros: true
|
||||||
|
AfterFunctionDefinitionName: false
|
||||||
|
AfterFunctionDeclarationName: false
|
||||||
|
AfterIfMacros: true
|
||||||
|
AfterOverloadedOperator: false
|
||||||
|
BeforeNonEmptyParentheses: false
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: Never
|
||||||
|
SpacesInConditionalStatement: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: -1
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
Standard: Latest
|
||||||
|
StatementAttributeLikeMacros:
|
||||||
|
- Q_EMIT
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 8
|
||||||
|
UseCRLF: false
|
||||||
|
UseTab: Never
|
||||||
|
WhitespaceSensitiveMacros:
|
||||||
|
- STRINGIZE
|
||||||
|
- PP_STRINGIZE
|
||||||
|
- BOOST_PP_STRINGIZE
|
||||||
|
- NS_SWIFT_NAME
|
||||||
|
- CF_SWIFT_NAME
|
||||||
|
...
|
||||||
|
|
4
Makefile
4
Makefile
@ -1,7 +1,7 @@
|
|||||||
all: tikker run
|
all: tikker run
|
||||||
|
|
||||||
tikker: tikker.c
|
tikker: tikker.c sormc.h
|
||||||
gcc tikker.c -Ofast -Wall -Wextra -pedantic -o tikker -lsqlite3
|
gcc tikker.c -Ofast -Wall -Werror -Wextra -o tikker -lsqlite3
|
||||||
|
|
||||||
run:
|
run:
|
||||||
./tikker
|
./tikker
|
||||||
|
48
sormc.h
48
sormc.h
@ -8549,7 +8549,6 @@ void sormd(int db);
|
|||||||
char *sormpt(char *sql, int number);
|
char *sormpt(char *sql, int number);
|
||||||
unsigned int sormcq(char *sql, char *out);
|
unsigned int sormcq(char *sql, char *out);
|
||||||
unsigned int sormpc(char *sql);
|
unsigned int sormpc(char *sql);
|
||||||
sqlite3_stmt *sormb(sorm_t *db, char *sql, ...);
|
|
||||||
sorm_ptr sormq(int db, char *sql, ...);
|
sorm_ptr sormq(int db, char *sql, ...);
|
||||||
char *sorm_csvc(int db, sqlite3_stmt *stmt);
|
char *sorm_csvc(int db, sqlite3_stmt *stmt);
|
||||||
char *sorm_csvd(int db, sqlite3_stmt *stmt);
|
char *sorm_csvd(int db, sqlite3_stmt *stmt);
|
||||||
@ -8571,18 +8570,14 @@ int sorm_instance_count = 0;
|
|||||||
|
|
||||||
int sormc(char *path) {
|
int sormc(char *path) {
|
||||||
// sorm connect
|
// sorm connect
|
||||||
printf("HIERR\n");
|
|
||||||
sorm_instance_count++;
|
sorm_instance_count++;
|
||||||
sorm_instance_count++;
|
sorm_instance_count++;
|
||||||
sorm_instances = realloc(sorm_instances, sorm_instance_count * sizeof(sorm_t *) + sorm_instance_count * sizeof(sorm_t));
|
sorm_instances = realloc(sorm_instances, sorm_instance_count * sizeof(sorm_t *) + sorm_instance_count * sizeof(sorm_t));
|
||||||
|
|
||||||
printf("HIERR\n");
|
sorm_t *db = (sorm_t *)&sorm_instances[sorm_instance_count - 1];
|
||||||
sorm_t *db = &sorm_instances[sorm_instance_count - 1];
|
|
||||||
|
|
||||||
printf("HIERR\n");
|
|
||||||
db->conn = NULL;
|
db->conn = NULL;
|
||||||
|
|
||||||
printf("HIERR\n");
|
|
||||||
db->csv = NULL;
|
db->csv = NULL;
|
||||||
db->current_column = 0;
|
db->current_column = 0;
|
||||||
db->current_row = 0;
|
db->current_row = 0;
|
||||||
@ -8597,10 +8592,9 @@ int sormc(char *path) {
|
|||||||
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db->conn));
|
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db->conn));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
printf("DONE!\n");
|
|
||||||
return sorm_instance_count;
|
return sorm_instance_count;
|
||||||
}
|
}
|
||||||
sorm_t *sormg(int ptr) { return &sorm_instances[ptr - 1]; }
|
sorm_t *sormg(int ptr) { return (sorm_t *)&sorm_instances[ptr - 1]; }
|
||||||
|
|
||||||
char *sormgcsv(int ptr) {
|
char *sormgcsv(int ptr) {
|
||||||
/* sorm get csv*/
|
/* sorm get csv*/
|
||||||
@ -8711,9 +8705,10 @@ Execute 3.35s, Format: 36.77s
|
|||||||
Memory usage: 537 GB, 96.026 allocated, 96.024 freed, 2 in use.
|
Memory usage: 537 GB, 96.026 allocated, 96.024 freed, 2 in use.
|
||||||
*/
|
*/
|
||||||
char *sorm_csvc(int db, sqlite3_stmt *stmt) {
|
char *sorm_csvc(int db, sqlite3_stmt *stmt) {
|
||||||
|
(void)db;
|
||||||
sormstr_t *str = sormstrn(512);
|
sormstr_t *str = sormstrn(512);
|
||||||
unsigned int column_count = sqlite3_column_count(stmt);
|
unsigned int column_count = sqlite3_column_count(stmt);
|
||||||
for (int i = 0; i < column_count; i++) {
|
for (uint i = 0; i < column_count; i++) {
|
||||||
const char *column_name = sqlite3_column_name(stmt, i);
|
const char *column_name = sqlite3_column_name(stmt, i);
|
||||||
sormstra(str, column_name);
|
sormstra(str, column_name);
|
||||||
sormstra(str, "(");
|
sormstra(str, "(");
|
||||||
@ -8728,7 +8723,7 @@ char *sorm_csvc(int db, sqlite3_stmt *stmt) {
|
|||||||
return sormstrc(str);
|
return sormstrc(str);
|
||||||
}
|
}
|
||||||
char *sorm_csvd(int sorm, sqlite3_stmt *stmt) {
|
char *sorm_csvd(int sorm, sqlite3_stmt *stmt) {
|
||||||
sorm_t *db = sormg(sorm);
|
(void)sorm;
|
||||||
int rc = SQLITE_ROW;
|
int rc = SQLITE_ROW;
|
||||||
int column_count = sqlite3_column_count(stmt);
|
int column_count = sqlite3_column_count(stmt);
|
||||||
/*
|
/*
|
||||||
@ -8755,7 +8750,7 @@ char *sorm_csvd(int sorm, sqlite3_stmt *stmt) {
|
|||||||
sprintf(temp, "%f", sqlite3_column_double(stmt, field_index));
|
sprintf(temp, "%f", sqlite3_column_double(stmt, field_index));
|
||||||
sormstra(str, temp);
|
sormstra(str, temp);
|
||||||
} else if (sqlite3_column_type(stmt, field_index) == SQLITE3_TEXT) {
|
} else if (sqlite3_column_type(stmt, field_index) == SQLITE3_TEXT) {
|
||||||
const char *temp = sqlite3_column_text(stmt, field_index);
|
const char *temp = ( char *)sqlite3_column_text(stmt, field_index);
|
||||||
sormstra(str, temp);
|
sormstra(str, temp);
|
||||||
} else {
|
} else {
|
||||||
// exit(1);
|
// exit(1);
|
||||||
@ -8774,7 +8769,6 @@ char *sorm_csvd(int sorm, sqlite3_stmt *stmt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *sorm_csv(int sorm, sqlite3_stmt *stmt) {
|
char *sorm_csv(int sorm, sqlite3_stmt *stmt) {
|
||||||
sorm_t *db = sormg(sorm);
|
|
||||||
sorm_row_count = 0;
|
sorm_row_count = 0;
|
||||||
char *column_names = sorm_csvc(sorm, stmt);
|
char *column_names = sorm_csvc(sorm, stmt);
|
||||||
char *data = sorm_csvd(sorm, stmt);
|
char *data = sorm_csvd(sorm, stmt);
|
||||||
@ -8789,31 +8783,16 @@ char *sorm_csv(int sorm, sqlite3_stmt *stmt) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_stmt *sormb(sorm_t *db, char *sql, ...) {
|
|
||||||
// Bind parameters to statement and return amount of parameters
|
|
||||||
int rc = 0;
|
|
||||||
sqlite3_stmt *stmt;
|
|
||||||
va_list args;
|
|
||||||
va_start(args, sql);
|
|
||||||
unsigned int number = 0;
|
|
||||||
char *clean_query = (char *)malloc(strlen(sql) + 1);
|
|
||||||
unsigned int parameter_count = sormcq(sql, clean_query);
|
|
||||||
free(clean_query);
|
|
||||||
|
|
||||||
return stmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *sormm(sorm_t *db) {
|
char *sormm(sorm_t *db) {
|
||||||
|
(void)db;
|
||||||
/* sormmemory */
|
/* sormmemory */
|
||||||
return rmalloc_stats();
|
return rmalloc_stats();
|
||||||
}
|
}
|
||||||
|
|
||||||
sorm_ptr sormq(int sorm, char *sql, ...) {
|
sorm_ptr sormq(int sorm, char *sql, ...) {
|
||||||
sorm_t *db = sormg(sorm);
|
sorm_t *db = sormg(sorm);
|
||||||
if (db->csv) {
|
|
||||||
// free(db->csv);
|
|
||||||
// db->csv = NULL;
|
|
||||||
}
|
|
||||||
_sorm_query_start = nsecs();
|
_sorm_query_start = nsecs();
|
||||||
db->time_query_start = nsecs();
|
db->time_query_start = nsecs();
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -8821,17 +8800,16 @@ sorm_ptr sormq(int sorm, char *sql, ...) {
|
|||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
sorm_ptr result = NULL;
|
sorm_ptr result = NULL;
|
||||||
char *clean_query = malloc(strlen(sql) + 1);
|
char *clean_query = malloc(strlen(sql) + 1);
|
||||||
unsigned int parameter_count = sormcq(sql, clean_query);
|
uint parameter_count = sormcq(sql, clean_query);
|
||||||
int rc = sqlite3_prepare_v2(db->conn, clean_query, -1, &stmt, 0);
|
int rc = sqlite3_prepare_v2(db->conn, clean_query, -1, &stmt, 0);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "%s\n", sqlite3_errmsg(db->conn));
|
fprintf(stderr, "%s\n", sqlite3_errmsg(db->conn));
|
||||||
}
|
}
|
||||||
free(clean_query);
|
free(clean_query);
|
||||||
int number = 0;
|
int number = 0;
|
||||||
for (int i = 0; i < parameter_count; i++) {
|
for (uint i = 0; i < parameter_count; i++) {
|
||||||
number++;
|
number++;
|
||||||
char *column_type = sormpt(sql, number);
|
char *column_type = sormpt(sql, number);
|
||||||
int arg_index = number - 1;
|
|
||||||
if (!strcmp(column_type, "int") || !strcmp(column_type, "integer") || !strcmp(column_type, "number")) {
|
if (!strcmp(column_type, "int") || !strcmp(column_type, "integer") || !strcmp(column_type, "number")) {
|
||||||
rc = sqlite3_bind_int(stmt, number, va_arg(args, int));
|
rc = sqlite3_bind_int(stmt, number, va_arg(args, int));
|
||||||
} else if (!strcmp(column_type, "int64")) {
|
} else if (!strcmp(column_type, "int64")) {
|
||||||
@ -8845,7 +8823,7 @@ sorm_ptr sormq(int sorm, char *sql, ...) {
|
|||||||
rc = sqlite3_bind_blob(stmt, number, data, size, SQLITE_STATIC);
|
rc = sqlite3_bind_blob(stmt, number, data, size, SQLITE_STATIC);
|
||||||
} else if (!strcmp(column_type, "text") || !strcmp(column_type, "str") || !strcmp(column_type, "string")) {
|
} else if (!strcmp(column_type, "text") || !strcmp(column_type, "str") || !strcmp(column_type, "string")) {
|
||||||
unsigned char *data = va_arg(args, unsigned char *);
|
unsigned char *data = va_arg(args, unsigned char *);
|
||||||
rc = sqlite3_bind_text(stmt, number, data, -1, SQLITE_STATIC);
|
rc = sqlite3_bind_text(stmt, number, (char *)data, -1, SQLITE_STATIC);
|
||||||
}
|
}
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Failed to bind parameters: %s\n", sqlite3_errmsg(db->conn));
|
fprintf(stderr, "Failed to bind parameters: %s\n", sqlite3_errmsg(db->conn));
|
||||||
@ -8904,7 +8882,7 @@ int sormlv(char *csv) {
|
|||||||
while (*csv) {
|
while (*csv) {
|
||||||
char *found = strstr(csv, ";");
|
char *found = strstr(csv, ";");
|
||||||
if (found) {
|
if (found) {
|
||||||
if (found - csv > longest)
|
if (found - csv > (long int)longest)
|
||||||
longest = found - csv;
|
longest = found - csv;
|
||||||
csv = csv + (found - csv) + 1;
|
csv = csv + (found - csv) + 1;
|
||||||
} else {
|
} else {
|
||||||
@ -8995,7 +8973,7 @@ char *sormfmt(char *csv) {
|
|||||||
sormstr_t *str = sormstrn(longest + 2);
|
sormstr_t *str = sormstrn(longest + 2);
|
||||||
while (*csv && (field = sormcsvn(csv))) {
|
while (*csv && (field = sormcsvn(csv))) {
|
||||||
sormstra(str, field);
|
sormstra(str, field);
|
||||||
for (int i = 0; i < longest - strlen(field); i++)
|
for (size_t i = 0; i < longest - strlen(field); i++)
|
||||||
sormstra(str, " ");
|
sormstra(str, " ");
|
||||||
|
|
||||||
csv += strlen(field);
|
csv += strlen(field);
|
||||||
@ -9049,3 +9027,5 @@ void sormfmtd(char *csv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user