A whole lot of other SQL statement types are also supported by DAME. You can generate code to insert, update and delete rows from databases. You can also use DAME for DDL statements like Create Table. However, I strongly suggest against using DAME for DDL as it might be much more easier to provide a set of SQL scripts to perform the same tasks.
In this chapter, we will have a look at general syntactic considerations for DAMEs support for non-select SQL statements.
nonselect.dame
options { header_suffix = ".hpp", source_suffix = ".cpp", strip_first_char = "false", lower_case_file_names = "false", use_namespace = "Dame::Example" } header { #include "emp.hpp" } class NonSelectDB (Dame::ExampleDb::emp) { int Empno ; char Name[11] ; char Job[10] ; int Manager ; double Salary ; double Commission ; int Deptno ; int Count ; char Deptname[16] ; date Hiredate ; /* * Inserting an emp record */ void Insert () { insert into emp (empno, ename, job, mgr, sal, comm, deptno, hiredate) values (:Empno, :Name, :Job, :Manager, :Salary, :Commission, :Deptno, to_date (:Hiredate, 'dd/mm/yyyy hh24:mi:ss')) } ; void UpdateByEmpno () { update emp set ename = :Name, job = :Job, mgr = :Manager, sal = :Salary, comm = :Commission, deptno = :Deptno, hiredate = to_date (:Hiredate, 'dd/mm/yyyy hh24:mi:ss') where empno = :Empno } ; } ; |
As you can observe, the usage of DAME for insert/update and delete statements is very similar to that of select statements. One major difference is that all of these functions returns void. The parameters can be passed either through emp object or through the function declarations.