Monday, September 30, 2013

SAP HANA exercise coding

Sample code



.xsaccess

{
"exposed":true,
"authentication":[{"method":"LogonTicket"},{"method":"Basic"}]

}



header.hdbtable

table.schemaName = "WorkshopA_00";
table.tableType = COLUMNSTORE ;
table.description = "workshop order header";
table.columns = [
{name = "orderID" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Createdby" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Createdat" ;sqlType = DATE ;nullable = false ;},
{name = "Currency" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Total" ;sqlType = DECIMAL ;nullable = false ;length = 10 ;
                                                   defaultValue = "0";}
];


table.primaryKey.pkcolumns = ["orderID"];


item.hdbtable

table.schemaName = "WorkshopG_00";
table.tableType = COLUMNSTORE ;
table.description = "workshop order item";
table.columns = [
{name = "orderID" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "OrderItem" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "ProductId" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Quantity" ;sqlType = NVARCHAR ;nullable = false ;length = 5 ;},
{name = "QuantityUnit" ;sqlType = NVARCHAR ;nullable = false ;length = 5;}
];


table.primaryKey.pkcolumns = ["orderID"];


.hdbview
to join the tables

schema="WorkshopA_00";
query="select T0.\"orderID\",
              T1.\"OrderItem\",
              T0.\"Createdby\",
              T0.\"Createdat\",
              T1.\"ProductId\",
              T1.\"Quantity\",
              T1.\"QuantityUnit\"
        from \"WorkshopA_00\".\"<package>::header\" T0
        left outer join \"WorkshopA_00\".\"<package>::item\" T1
        on T0.\"orderID\" = T1.\"orderID\"
        order by T0.\"orderID\" ASC";
        depends_on_table =["<package>::header","<package>::item"];



header.hdbsequence

schema = "WorkshopA_00";
start_with = 1 ;

depends_on_table = "package::header";



.xsprivileges

{
    "privileges":[
        {
            "name": "Basic",
            "description":"Basic usage privileges"
        },
        {
            "name": "Admin",
            "description":"Administration privileges"
        }

             ]
}

workshopAdmin.hdbrole

role <package>::workshopAdmin
 extends role <package>::workshopUser
{
catalog schema "WorkshopA_00": SELECT ,INSERT ,UPDATE ,DELETE ,DROP ;
application privilege : <package>::Admin;
}

workshopUser.hdbrole 

role <package>::workshopUser {

catalog schema "WorkshopA_00": SELECT ;
application privilege : <package>::Basic;
}


To Activate role
call "_SYS_REPO"."GRANT_ACTIVATED_ROLE" ('package::workshopAdmin','uname');

SAP HANA Error / Solution

Recently I have encountered a problem while create table in SAP HANA  , I had no clue about the error .. I was getting the error from below

table.columns = [
{name = "orderID" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Createdby" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Createdat" ;sqlType = DATE ;nullable = false ;},
{name = "Currency" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Total" ;sqlType = DECIMAL ;nullable = false ;length = 10 ;
                                                   defaultValue = "0";}

];

Error is "unable to parse  '{' expected "  .

later I found that , there is an empty line between the data and the square bracket ..

I just deleted the empty line and starting working .. quite strange :(
Hope this helps someone who is facing this issue.




Similar problem I come across recent days is that

Error : The processing instruction target matching "[xX][mM][lL]" is not allowed.

above error is occured while parsing the xml file by the application

Soln :  you might have added some space in the beginning of the application , just remove the space and f5 .



Wednesday, September 25, 2013

Encryption / decryption of DB in android ( Sqlchiper )

Encrypting database 

below link will help you , how to encrypt your data

http://sqlcipher.net/sqlcipher-for-android/


Decryption of database 

once you encrypted your db , you may need to decrypt your database .
follow below steps to decrypt your database

you need linux system to decrypt your database  or follow
http://thebugfreeblog.blogspot.in/2012/08/compiling-sqlcipher-for-windows.html  this link

download sqlcipher_2.1.1.orig.tar.gz from the below site
https://launchpad.net/ubuntu/+source/sqlcipher/2.1.1-2

or run
$ wget https://launchpad.net/ubuntu/+archive/primary/+files/sqlcipher_2.1.1.orig.tar.gz
#untar using below command
$ tar -zxvf sqlcipher_2.1.1.orig.tar.gz
$ apt-get install build-essential
$ sudo apt-get install libssl-dev
# $ cd sqlcipher-2.1.1  , go to that folder
$  ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"
$  make
$ ./sqlite3 encrypted.db ;

sqlite> PRAGMA key = 'password';   -- you need to pass the password which is used while creating db.
sqlite> ATTACH DATABASE 'plaintext.db' AS plaintext KEY '';  -- empty key will disable encryption
sqlite> SELECT sqlcipher_export('plaintext');
sqlite> DETACH DATABASE plaintext;


you will get plaintext.db , you can view in SQLite Database Browser