/*! * \brief バージョン1にアップデート */ void SequenceLogServiceDB::updateVersion1() const throw(Exception) { SLOG(CLS_NAME, "updateVersion1"); Statement* stmt = nullptr; try { // バージョン情報テーブル作成 query( "create table version_info(" " version int not null);"); // バージョン登録 stmt = newStatement(); stmt->prepare("insert into version_info (version) values (1)"); stmt->execute(); delete stmt; stmt = nullptr; // アカウントテーブル作成 #if defined(USE_SQLITE) query( "create table user(" " id integer primary key autoincrement," " name varchar not null unique," " password varchar not null," " mail_addr varchar," " version int not null default 1," " admin int not null default 0);"); #else query( "create table user(" " id int primary key auto_increment," " name varchar(20) not null unique," " password varchar(64) not null," " mail_addr varchar(256)," " version tinyint not null default 1," " admin tinyint not null default 0);"); #endif // 初期アカウント登録(パスワード:gols) stmt = newStatement(); stmt->prepare("insert into user (name, password, admin) values ('slog', 'RrtQzcEv7FQ1QaazVN+ZXHHAS/5F/MVuDUffTotnFKk=', 1)"); stmt->execute(); } catch (Exception e) { SMSG(slog::DEBUG, "%s", e.getMessage()); delete stmt; throw e; } delete stmt; }
statementType * addLabelToStatement(labelListType *labelList, statementType *statement) { statementType *newStatement(statementKindType kind, statementBodyType body); if (statement == NULL) statement = newStatement(NULL_STATEMENT, (statementBodyType){ NULL }); statement->labels = labelList; return(statement); }
/*! * \brief データベースバージョン取得 * * \return データベースバージョン */ int32_t SequenceLogServiceDB::getVersion() const { SLOG(CLS_NAME, "getVersion"); int32_t version = 0; Statement* stmt = nullptr; try { const char* sql = "select version from version_info"; stmt = newStatement(); stmt->prepare(sql); stmt->setIntResult(0, &version); stmt->bind(); stmt->execute(); stmt->fetch(); } catch (Exception e) { // 初回起動時などテーブルが存在しない場合もあるので、 // 例外が発生しても何もすることはない SMSG(slog::DEBUG, "%s", e.getMessage()); } delete stmt; return version; }
statementType * buildMifStatement(mifHeadType *head, mifContinuationType continuation, ifContinuationKindType continuationKind) { mifStatementBodyType *result; result = typeAlloc(mifStatementBodyType); result->mifCondition = head->headCondition; result->mifConsequence = head->headBody; if (continuationKind == NO_CONTINUATION) result->mifContinuation.mifContinuationBodyUnion = NULL; else if (continuationKind == ELSE_CONTINUATION) { result->mifContinuation.mifContinuationBodyUnion = typeAlloc(mifContinuationBodyType); result->mifContinuation.mifContinuationBodyUnion-> mifCondition = NULL; result->mifContinuation.mifContinuationBodyUnion-> mifConsequence = continuation.mifBlockUnion; result->mifContinuation.mifContinuationBodyUnion-> mifContinuation.mifContinuationBodyUnion = NULL; } else if (continuationKind == ELSEIF_CONTINUATION) result->mifContinuation = continuation; else botch("bad mif continuation kind: %d\n", continuationKind); qfree(head); return(newStatement(MIF_STATEMENT, (statementBodyType) result)); }
statementType * buildMdoUntilStatement(blockType *body, struct expressionTermStruct *condition) { mdoUntilStatementBodyType *result; result = typeAlloc(mdoUntilStatementBodyType); result->mdoUntilCondition = condition; result->mdoUntilLoop = body; return(newStatement(MDO_UNTIL_STATEMENT, (statementBodyType) result)); }
statementType * buildDoWhileStatement(blockType *body, conditionType condition) { doWhileStatementBodyType *result; result = typeAlloc(doWhileStatementBodyType); result->doWhileCondition = condition; result->doWhileLoop = body; return(newStatement(DO_WHILE_STATEMENT, (statementBodyType) result)); }
statementType * buildMdefineStatement(stringType *name, expressionType *value) { mdefineStatementBodyType *result; result = typeAlloc(mdefineStatementBodyType); result->theSymbol = lookupOrEnterSymbol(name, DEAD_SYMBOL); result->theValue = value; return(newStatement(MDEFINE_STATEMENT, (statementBodyType) result)); }
statementType * buildMswitchStatement(expressionType *switchExpression, caseListType *cases) { mswitchStatementBodyType *result; result = typeAlloc(mswitchStatementBodyType); result->switchExpression = switchExpression; result->cases = cases; return(newStatement(MSWITCH_STATEMENT, (statementBodyType) result)); }
statementType * buildDoUntilStatement(blockType *body, conditionType condition) { doUntilStatementBodyType *result; result = typeAlloc(doUntilStatementBodyType); result->doUntilCondition = condition; result->doUntilLoop = body; return(newStatement(DO_UNTIL_STATEMENT, (statementBodyType) result)); }
statementType * buildMdoWhileStatement(blockType *body, expressionType *condition) { mdoWhileStatementBodyType *result; result = typeAlloc(mdoWhileStatementBodyType); result->mdoWhileCondition = condition; result->mdoWhileLoop = body; return(newStatement(MDO_WHILE_STATEMENT, (statementBodyType) result)); }
statementType * buildMwhileStatement(expressionType *condition, blockType *body) { mwhileStatementBodyType *result; result = typeAlloc(mwhileStatementBodyType); result->mwhileCondition = condition; result->mwhileLoop = body; return(newStatement(MWHILE_STATEMENT, (statementBodyType) result)); }
statementType * buildMvariableStatement(stringType *name, expressionListType *value, expressionType *dimension) { mvariableStatementBodyType *result; result = typeAlloc(mvariableStatementBodyType); result->theSymbol = lookupOrEnterSymbol(name, DEAD_SYMBOL); result->theValue = value; result->theDimension = dimension; return(newStatement(MVARIABLE_STATEMENT, (statementBodyType) result)); }
statementType * buildMacroInstructionStatement(macroTableEntryType *macro, operandListType *operands) { instructionStatementBodyType *result; result = typeAlloc(instructionStatementBodyType); result->kindOfInstruction = MACRO_INSTRUCTION; result->theInstruction.macroUnion = macro; result->theOperands = operands; return(newStatement(INSTRUCTION_STATEMENT, (statementBodyType) result)); }
statementType * buildMacroStatement(macroTableEntryType *macro, argumentDefinitionListType *arguments, blockType *body) { macroStatementBodyType *result; result = typeAlloc(macroStatementBodyType); result->theMacro = macro; result->theArguments = arguments; result->theBlock = body; return(newStatement(MACRO_STATEMENT, (statementBodyType) result)); }
statementType * buildInstructionStatement(opcodeTableEntryType *opcode, operandListType *operands) { instructionStatementBodyType *result; result = typeAlloc(instructionStatementBodyType); result->kindOfInstruction = OPCODE_INSTRUCTION; result->theInstruction.opcodeUnion = opcode; result->theOperands = operands; return(newStatement(INSTRUCTION_STATEMENT, (statementBodyType) result)); }
statementType * buildConstrainStatement(expressionType *expression, blockType *block) { constrainStatementBodyType *result; result = typeAlloc(constrainStatementBodyType); result->constraint = expression; result->constrainedBlock = block; return(newStatement(CONSTRAIN_STATEMENT, (statementBodyType) result)); }
Statement *newReturnStatement(Scope *scope, Expression *returnValue) { ReturnStatement *returnStatement = malloc(sizeof(ReturnStatement)); returnStatement->returnValue = returnValue; Statement *stmt = newStatement(); stmt->stmt_return = returnStatement; stmt->type = ST_RETURN; typeCheckStatement(scope, stmt); return stmt; }
Statement *newFunctionCallStatement(Scope *scope, Expression *functionCall) { FunctionCallStatement *callStatement = malloc(sizeof(FunctionCallStatement)); callStatement->functionCall = functionCall; Statement *stmt = newStatement(); stmt->stmt_func = callStatement; stmt->type = ST_FUNC; typeCheckStatement(scope, stmt); return stmt; }
statementType * buildAssertStatement(expressionType *condition, expressionType *message) { assertStatementBodyType *result; result = typeAlloc(assertStatementBodyType); result->condition = condition; result->message = message; return(newStatement(ASSERT_STATEMENT, (statementBodyType) result)); }
Statement *newIfStatement(Scope *scope, Expression *condition, Statement *body) { IfStatement *ifStatement = malloc(sizeof(IfStatement)); ifStatement->condition = condition; ifStatement->satisfied = body; Statement *stmt = newStatement(); stmt->stmt_if = ifStatement; stmt->type = ST_IF; typeCheckStatement(scope, stmt); return stmt; }
Statement *newWhileStatement(Scope *scope, Expression *condition, Statement *body) { WhileStatement *whileStatement = malloc(sizeof(WhileStatement)); whileStatement->condition = condition; whileStatement->body = body; Statement *stmt = newStatement(); stmt->stmt_while = whileStatement; stmt->type = ST_WHILE; typeCheckStatement(scope, stmt); return stmt; }
static bool execInternal(const char *stmt, int mode) { bool notfound = false; newStatement(); if(!prepareInternal(stmt)) return false; /* error */ if(!rv_numRets) { if(!(mode & 1)) { showStatement(); errorPrint("2SQL select statement returns no values"); } notfound = true; } else { /* end no return values */ if(!(mode & 2)) { showStatement(); errorPrint("2SQL statement returns %d values", rv_numRets); } } if(!openfirst) rc = SQLExecute(hstmt); if(!rc) { /* statement succeeded */ /* fetch the data, or get a count of the rows affected */ if(rv_numRets) { stmt_text = "fetch"; debugStatement(); rc = SQLFetchScroll(hstmt, (ushort) SQL_FD_FETCH_NEXT, 1); if(rc == SQL_NO_DATA) { rc = SQL_SUCCESS; notfound = true; } else everything_null = false; } else { rc = SQLRowCount(hstmt, &rv_lastNrows); if(sql_debug) appendFile(sql_debuglog, "%d rows affected", rv_lastNrows); if(sql_debug2) printf("%d rows affected\n", rv_lastNrows); } } if(errorTrap(0)) return false; if(!rv_numRets) return true; return !notfound; } /* execInternal */
Statement *newIfElseStatement(Scope *scope, Expression *condition, Statement *satisfied, Statement *unsatisfied) { IfElseStatement *ifElseStatement = malloc(sizeof(IfElseStatement)); ifElseStatement->condition = condition; ifElseStatement->satisfied = satisfied; ifElseStatement->unsatisfied = unsatisfied; Statement *stmt = newStatement(); stmt->stmt_if_else = ifElseStatement; stmt->type = ST_IF_ELSE; typeCheckStatement(scope, stmt); return stmt; }
Statement *newAssignmentStatement(Scope *scope, char *identifier, Expression *arrayIndex, Expression *expression) { AssignmentStatement *assign = malloc(sizeof(AssignmentStatement)); assign->identifier = identifier; assign->arrayIndex = arrayIndex; assign->expression = expression; Statement *stmt = newStatement(); stmt->stmt_assign = assign; stmt->type = ST_ASSIGN; typeCheckStatement(scope, stmt); return stmt; }
statementType * buildMforStatement(forExpressionsType *forExpressions, blockType *body) { mforStatementBodyType *result; result = typeAlloc(mforStatementBodyType); result->initExpression = forExpressions->initExpression; result->testExpression = forExpressions->testExpression; result->incrExpression = forExpressions->incrExpression; result->forLoop = body; qfree(forExpressions); return(newStatement(MFOR_STATEMENT, (statementBodyType) result)); }
void sql_deferConstraints(void) { if(!translevel) errorPrint("2Cannot defer constraints unless inside a transaction"); stmt_text = "defere constraints"; debugStatement(); /* is there a way to do this through ODBC? */ newStatement(); rc = SQLExecDirect(hstmt, (char *)stmt_text, SQL_NTS); errorTrap(0); SQLFreeHandle(SQL_HANDLE_STMT, hstmt); exclist = 0; } /* sql_deferConstraints */
/* display foreign keys, from this table to others */ bool fetchForeign(char *tname) { char farschema[40], fartab[40]; char farcol[40]; char nearcol[40]; SQLLEN nearcolOut, farschemaOut, fartabOut, farcolOut; char *dot; newStatement(); stmt_text = "foreign keys"; debugStatement(); dot = strchr(tname, '.'); if(dot) *dot++ = 0; rc = SQLForeignKeys(hstmt, NULL, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS, (dot ? tname : NULL), SQL_NTS, (dot ? dot : tname), SQL_NTS); if(dot) dot[-1] = '.'; if(rc) goto abort; SQLBindCol(hstmt, 2, SQL_CHAR, (SQLPOINTER) farschema, sizeof (farschema), &farschemaOut); SQLBindCol(hstmt, 3, SQL_CHAR, (SQLPOINTER) fartab, sizeof (fartab), &fartabOut); SQLBindCol(hstmt, 4, SQL_CHAR, (SQLPOINTER) farcol, sizeof (farcol), &farcolOut); SQLBindCol(hstmt, 8, SQL_CHAR, (SQLPOINTER) nearcol, sizeof (nearcol), &nearcolOut); while(SQLFetch(hstmt) == SQL_SUCCESS) { printf("%s > ", nearcol); if(farschema[0]) printf("%s.", farschema); printf("%s.%s\n", fartab, farcol); } SQLFreeHandle(SQL_HANDLE_STMT, hstmt); return true; abort: SQLFreeHandle(SQL_HANDLE_STMT, hstmt); return false; } /* fetchForeign */
/* Constructor functions for Statements */ Statement *newForStatement(Scope *scope, Statement *initial, Expression *condition, Statement *change, Statement *body) { ForStatement *forStatement = malloc(sizeof(ForStatement)); forStatement->initial = initial; forStatement->condition = condition; forStatement->change = change; forStatement->body = body; Statement *stmt = newStatement(); stmt->stmt_for = forStatement; stmt->type = ST_FOR; typeCheckStatement(scope, stmt); return stmt; }
bool showTables(void) { char tabname[40]; char tabtype[40]; char tabowner[40]; SQLLEN tabnameOut, tabtypeOut, tabownerOut; char *buf; int buflen, cx; int truevalue = SQL_TRUE; /* SQLSetConnectAttr(hdbc, SQL_ATTR_METADATA_ID, &truevalue, SQL_IS_INTEGER); */ newStatement(); stmt_text = "get tables"; debugStatement(); rc = SQLTables(hstmt, NULL, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS); if(rc) goto abort; SQLBindCol(hstmt, 2, SQL_CHAR, (SQLPOINTER) tabowner, sizeof (tabowner), &tabownerOut); SQLBindCol(hstmt, 3, SQL_CHAR, (SQLPOINTER) tabname, sizeof (tabname), &tabnameOut); SQLBindCol(hstmt, 4, SQL_CHAR, (SQLPOINTER) tabtype, sizeof (tabtype), &tabtypeOut); buf = initString(&buflen); while(SQLFetch(hstmt) == SQL_SUCCESS) { char tabline[140]; sprintf(tabline, "%s.%s|%s\n", tabowner, tabname, tabtype); stringAndString(&buf, &buflen, tabline); } cx = sideBuffer(0, buf, buflen, 0, false); nzFree(buf); i_printf(MSG_ShowTables, cx); SQLFreeHandle(SQL_HANDLE_STMT, hstmt); return true; abort: SQLFreeHandle(SQL_HANDLE_STMT, hstmt); return false; } /* showTables */
statementType * buildFunctionStatement(stringType *name, argumentDefinitionListType *arguments, blockType *body) { functionStatementBodyType *result; symbolTableEntryType *testSymbol; testSymbol = lookupOrEnterSymbol(name, FUNCTION_SYMBOL); if (testSymbol->context->usage != FUNCTION_SYMBOL && testSymbol-> context->usage != UNKNOWN_FUNCTION_SYMBOL) { error(SYMBOL_ALREADY_THERE_ERROR, symbName(testSymbol)); return(NULL); } result = typeAlloc(functionStatementBodyType); result->functionName = saveString(name); result->theArguments = arguments; result->theBlock = body; return(newStatement(FUNCTION_STATEMENT, (statementBodyType) result)); }