sqlcipher attach database - sqlcipher

I am following the example at the sqlcipher Api docs : http://sqlcipher.net/sqlcipher-api#attach
ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'secret'; -- create a new encrypted database
CREATE TABLE encrypted.t1(a,b); -- recreate the schema in the new database (you can inspect all objects using SELECT * FROM sqlite_master)
INSERT INTO encrypted.t1 SELECT * FROM t1; -- copy data from the existing tables to the new tables in the encrypted database
DETACH DATABASE encrypted;
The first line CREATE TABLE encrypted.t1(a,b); has (a,b) and the second
INSERT INTO encrypted.t1 SELECT * FROM t1; does not.
Why is there an(a,b) in the first line and what is it for?.

In this case a and b are the column names. The introduction to that example in the docs explains the important point "assume you have a standard SQLite database called unencrypted.db with a single table, t1(a,b)." Then:
The first line attaches a new encrypted database.
Next, a second table is created in the encrypted database with the same name and column specification.
The third line selects all the data out of the original table and inserts it into the new table in the encrypted database.
Because the columns on the two tables are identical it is not necessary to list the table columns explicitly.

Related

Creating txt file using Pentaho

I'm currently trying to create txt files from all tables in the dbo schema
I have like 200s-300s tables there, so it would takes up too much times to create it manually..
I was thinking for creating a loop.
so as example (using AdventureWorks2019) :
select t.name as table_name
from sys.tables t
where schema_name(t.schema_id) = 'Person'
order by table_name;
This would get all the table name within the Person schema.
So I would loop :
Table input : select * from ${table_name}
But then i realized that for txt files, i need to declare all the field and their data types in pentaho, so it would become a problems.
Any ideas how to do this "backup" txt files?
Using Metadata Injection and more queries to the schema catalog tables in SQL Server. You not only need to retrieve the table name, you would need to afterwards retrieve the columns in that table and the data types, and inject that information (metadata) to the text output step.
You have in the samples directory of your spoon installation an example on how to use Metadata Injection, use it, along with the documentation, to build a simple example (the check to generate a transformation with the metadata you have injected is of great use to debug)
I have something similar to copy data from one database to another, both in Oracle, but with SQL Server you have similar catalog tables as in Oracle to retrieve the information you need. I created a simple, almost empty transformation to read one table and write to another. This transformation has almost no information, only the database origin in the Table Input step and the target database in the Table Output step:
And then I have a second transformation where I fill up all the information (metadata) to inject: The query to perform in the Table Input step, and all the data I need in the Table Output: Target table, if I need to truncate before inserting, the columns from (stream field) and to (Table field):

Populate data from DB and save as new record oracle forms

I Have populated master detail block from Data based want to change some values in data block and save it as a new record in Both master and child tables.
To Populate used execute query
Changed values as record
Save by commit
But as i used execute query to populate existing data on commit it is trying to update already saved data in table. But i want to create new records in DB with new primary key
That won't work, as you noticed. Records you fetched are database records so - once you update their values and commit, you overwrite data.
If you want to insert new records, then
add them into new rows - you can do that manually (by typing those values), or
you can duplicate one of previous records into a new record (use Forms menu for that or a shortcut key; look for "duplicate record" option) and modify that duplicated record.
Alternatively, don't use data block but control block (the one that isn't based on a database table). Populate it, somehow (e.g. you could create a button which calls the procedure; it uses a loop and populates record-by-record). Modify values you want and create your own procedure which will insert new rows into the database table. As of the primary key, it depends on how you do it; if it is a database trigger which uses a sequence, it (the trigger) will do the job. Otherwise, you'll have to create a primary key yourself (during the insert process).

DDL sync informatica

I have a question: I have a table (say tableA) in a database (say dbA) and I need to mirror tableA as another table (say tableB) in another database (say dbB).
I know this can be done via (materialised) view or via informatica. But by problem is that I need to sync DDL as well. For example if a column is added in tableA, the column should automatically reflect in tableB.
Can this be done anyway directly via oracle or Informatica.
(or I will have to write a procedure to sync table on basis of all_tab_cols).
Yes, you could:
create another database as a logical standby database with Data Guard
use Oracle Streams
I would use (2) if you just need a single table in the other database or (1) if you need an entire schema (or more).

create a backup table with all parameter

I'm trying to move the data from one table TABLE5 another one TABLE5_BKP.
CREATE TABLE TABLE5_BKP AS SELECT * FROM TABLE5;
The table created and the data moved. when I checked the constraints,
The primary key,foreign key etc are not generated but all other constraints like,
SYS_C2211111 Check "COLUMN1" IS NOT NULL
etc are created. What to do in this case? Need to create the primary key,foreign key etc separately? What about indexes and other parameters, which I was not able to check.
You can't implicitly create PK, FK, Indexes, etc. just using
CREATE TABLE tablename AS SELECT *...
You have to specify them after creating. Also I suggest you to use oracle tools, like exp/imp, data pump, etc. if you want to move the database structure from one database to another.

How to create a table identical to other table in structure and constraints in Oracle?

I want to create a table (lets say table_copy) which has same columns as other table (lets call it table_original) in Oracle database, so the query will be like this :
create table table_copy as (select * from table_original where 1=0);
This will create a table, but the constraints of table_original are not copied to table_copy, so what should be done in this case?
Only NOT NULL constraints are copied using Create Table As Syntax (CTAS). Others should be created manually.
You might however query data dictionary view to see the definitions of constraints and implement them on your new table using PL/SQL.
The other tool that might be helpful is Oracle Data Pump. You could import the table using REMAP_TABLE option specifying the name for the new table.
Use a database tool to extract the DDL needed for the constraints (SQL Developer does the job). Edit the resulting script to match the name of the new class.
Execute the script.
If you need to do this programmatically you can use a statement like this:
DBMS_METADATA.GET_DDL('TABLE','PERSON') from DUAL;

Resources