Skip to content

Commit

Permalink
Tiny docs tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtv committed Dec 27, 2017
1 parent 8bd90f6 commit 59d3a0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/pqxx/doc/accessing-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ C++ containers of fields. So the easiest way to go through them is:
}

But results and rows also support other kinds of access. Array-style
indexing, for instance:
indexing, for instance, such as `r[rownum]`:

const int num_rows = r.size();
for (int rownum=0; rownum < num_rows; ++rownum)
Expand Down
6 changes: 3 additions & 3 deletions include/pqxx/doc/escaping.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ Here's how you can fix the problem in the example above:
"FROM accounts "
"WHERE allowed_to_see('" + TX.esc(userid) + "', "
"'" + TX.esc(password) + "')");

Now, the quotes embedded in the attacker's string will be neatly escaped so
they can't "break out" of the quoted SQL string they were meant to go into:

SELECT number,amount
FROM accounts
WHERE allowed_to_see('user', 'x'') OR (''x'' = ''x')

If you look carefully, you'll see that thanks to the added escape characters
(a single-quote is escaped in SQL by doubling it) all we get is a very
strange-looking password string--but not a change in the SQL statement.
Expand Down
14 changes: 7 additions & 7 deletions include/pqxx/doc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ They fit together as follows:

* You create a transaction object (see @ref transaction) operating on that
connection. You'll usually want the `pqxx::work` variety.

Once you're done you call the transaction's `commit` function to make its
work final. If you don't call this, the work will be rolled back when the
transaction object is destroyed.
Expand All @@ -27,7 +27,7 @@ They fit together as follows:
array indexing or iterators to access either.

* The field's data is stored internally as a text string.

You can read it as such using its `c_str` function, or convert it to other
types using its `as` and `to` member functions. These are templated on the
destination type: `myfield.as<int>();` or `myfield.to(myint);`
Expand All @@ -41,28 +41,28 @@ an `int`, and prints it out. It also contains some basic error handling.

#include <iostream>
#include <pqxx/pqxx>

int main()
{
try
{
// Connect to the database. In practice we may have to pass some
// arguments to say where the database server is, and so on.
pqxx::connection c;

// Start a transaction. In libpqxx, you always work in one.
pqxx::work w(c);

// work::exec1() executes a query returning a single row of data.
// We'll just ask the database to return the number 1 to us.
pqxx::row r = w.exec1("SELECT 1");

// Commit your transaction. If an exception occurred before this
// point, execution will have left the block, and the transaction will
// have been destroyed along the way. In that case, the failed
// transaction would implicitly abort instead of getting to this point.
w.commit();

// Look at the first and only field in the row, parse it as an integer,
// and print it.
std::cout << r[0].as<int>() << std::endl;
Expand Down

0 comments on commit 59d3a0f

Please sign in to comment.