OCILIB Tutorials v5.0.0
Intermediate

Checkpoint 1 — build a query console

You should now be able to run the full statement cycle: prepare → bind → execute → fetch → getters, plus RETURNING, scrollable mode and piecewise LONGs.

The exercise — qtool

Write a small program that works like a pocket sqlplus:

  1. Connect with OCILIB_DEMO_* (or argv[1..3] overrides).
  2. Loop reading a line of SQL from stdin until quit.
  3. If the line starts with :set fetchsize N, call OCI_StatementSetFetchSize(st, N).
  4. Otherwise execute it: - for select/with/describe-able statements: print a header using OCI_ResultsetGetColumnCount + OCI_ColumnGetName/GetSize, then rows with OCI_ResultsetGetString on every column (universal getter fallback); - for DML/DDL: print OCI_StatementGetSqlVerb + OCI_StatementGetAffectedRows.
  5. Report errors through your handler and keep looping — the tool must not die on ORA-00942.

Stretch goals

What it exercises

Skill Pages
env + connection + error handler 060–080
Execute vs Prepare, affected rows, SQL verb 210
Column metadata, header rendering 225/240
Generic getters, NULLs 225/230
Fetch tuning 270
Scrollable, RETURNING 275/280

Suggested acceptance checks

> select ename, sal from employees where deptno = 20
ENAME       SAL
JONES      2975
FORD       3000
2 row(s)

> update employees set comm = 0 where comm is null
UPDATE -> 5 row(s)

> select * from nope
ORA-00942: table or view does not exist

If it runs without crashing on bad SQL, prints a formatted table, and survives a quit — Part 3 is done. Onward to PL/SQL.