예제 #1
0
        string modify_query::to_string() const
        {
            ostringstream buf;

            buf << "REPLACE INTO " << tableName_;

            if (columns_.size() > 0)
            {
                buf << "(";

                buf << join_csv(columns_);

                buf << ") VALUES (";

                buf << join_csv('?', columns_.size());

                buf << ")";
            }
            else
            {
                buf << " DEFAULT VALUES";
            }

            return buf.str();
        }
예제 #2
0
        string select_query::to_string() const
        {
            ostringstream buf;

            buf << "SELECT ";

            buf << (columns_.size() == 0 ? "*" : join_csv(columns_));

            buf << " FROM " << tableName_;

            if (!where_.empty())
            {
                buf << " WHERE " << where_.to_string();
            }

            if (!orderBy_.empty())
            {
                buf << " ORDER BY " << orderBy_;
            }

            if (!limit_.empty())
            {
                buf << " LIMIT " << limit_;
            }

            if (!groupBy_.empty())
            {
                buf << " GROUP BY " << groupBy_;
            }

            return buf.str();
        }
예제 #3
0
        string session_impl::insert_sql(const std::shared_ptr<schema> &schema, const vector<string> &columns) const
        {
            ostringstream buf;

            buf << "INSERT INTO " << schema->table_name();

            buf << "(";

            buf << join_csv(columns);

            buf << ") VALUES(";

            buf << join_params(columns, false);

            buf << ");";

            return buf.str();
        }
예제 #4
0
        string select_query::to_string() const
        {
            ostringstream buf;

            buf << "SELECT ";

            buf << (columns_.size() == 0 ? "*" : join_csv(columns_));

            buf << " FROM " << tableName_;

            if (!join_.empty()) {
                for (auto &join : join_) {
                    buf << join;
                }
            }

            if (!where_.empty()) {
                buf << " WHERE " << where_.to_string();
            }

            if (!orderBy_.empty()) {
                buf << " ORDER BY " << orderBy_;
            }

            if (!limit_.empty()) {
                buf << " LIMIT " << limit_;
            }

            if (!groupBy_.empty()) {
                buf << " GROUP BY " << groupBy_;
            }

            if (union_) {
                buf << " UNION ";
                if (union_->type == union_op::all) {
                    buf << "ALL ";
                }
                buf << union_->query;
            } else {
                buf << ";";
            }
            return buf.str();
        }