void Exp(const char *s, SqlStatement sql) { DDUMP(s); DDUMP(sql.Get(PGSQL)); qtf << "\n:: "; Put(s, ".From;.Where;.OrderBy"); qtf << "\n:: "; Put(SqlCompile(PGSQL, sql.Get(PGSQL)), " from; where; order by"); }
//============================================================================================== // Save the new test row data to the database. void TestGrid::SaveTest(bool prompt) { ASSERT(connection); ASSERT(connection->session->IsOpen()); ASSERT(IsCursor()); int row = GetCursor(); SqlStatement sts; // Inserting a new test if (IsNewRow()) { Set(PROCESSORDER, GetNextProcessOrder()); sts = SqlStatement(SqlInsert(TESTS)(THISBACK(FieldLayout), true /*nokey, let database generate from sequence */)); if (WhenToolBarNeedsUpdating) WhenToolBarNeedsUpdating(UrpGrid::USERADDEDROW); // Updating an existing test } else { sts = SqlStatement(SqlUpdate(TESTS)(THISBACK(FieldLayout)).Where(TESTID == Get(TESTID))); if (WhenToolBarNeedsUpdating) WhenToolBarNeedsUpdating(UrpGrid::USERCHANGEDDATA); } // Wrap in a SqlStatement object, which will somehow either call the SqlUpdate or // SqlInsert operator SqlStatement() const, which then constructs a string and forms // the constructor "explicit SqlStatement(const String& s) : text(s) {}", and so // sets the text member. I don't know what the explicit command means. // Transform to proper Sql; Sql will not be properly formed until the dialect of the // connection is determined, in this case PGSQL. Do not use GetText(). // This calls SqlCompile(dialect, text) to finalize the "text" member contents. String controlScript = sts.Get(connection->GetDialect()); LOG(controlScript); int rsp = 1; if (prompt) { rsp = PromptOKCancel(CAT << "Script being applied: " << controlScript); } if (rsp == 1) { if (!connection->SendAddDataScript(controlScript)) { // Beep return; } if (IsNewRow()) { if (connection->GetRowsProcessed() > 0) { int testid = connection->GetInsertedId("tests", "testid"); if (testid >= 0) { SetTestId(row, testid); } } } } }
String Sql::Compile(const SqlStatement& s) { byte dialect = GetDialect(); ASSERT(dialect); return s.Get(dialect); }