{C++ etc.}

Latest Posts
 
Home | C++ Posts | Linux Posts | Programming Posts | Issue Tracking Posts

Thursday, May 21, 2009

Altering the primary key of an Oracle Table

Eg: Table T_1 has the following columns:
T_1
--------------
NAME VARCHAR2(100) not null (primary key)
AGE INT
ID VARCHAR2(100)
PASS VARCHAR

NAME is the primary key.
If we want to add INT to the primary key and make it a composite key:
1. We must first make the ID column "not null" which means it could not have any NULL entries.
2. We should drop the existing primary key.
3. Create the new primary key.


PL/SQL script to achive this:

alter table T_1 modify NAME VARCHAR2(100) NOT NULL;
alter table T_1 drop primary key;
alter table T_1 add primary key (NAME, ID);
commit;

:)

Sunday, May 03, 2009

STL containers for message buffers in socket(-like) communications

I always wondered why custom buffer classes were used in most of our (high performance) libraries. This post made me realize that STL, as extensively used as it is, is not a golden hammer.

Tuesday, April 28, 2009

C++ Comma Confusion via LightSleeper

Many C++ programmers are surprised by the effects of that little comma. In some cases (e.g. comma operator), the comma very clearly describes the order of operations. In other cases (e.g. function parameter separators), the comma does not describe the order. h() could execute before g() in the last example, and it often does in real compilers. Understanding the difference is well worth your time.


Original Post

Thursday, April 23, 2009

awk Search script with prior and following line capability

#!/bin/sh
# *********************************************************
# This uses nawk to list lines coming prior to and after
# the given search string.
# Format: xgrep
# ********************************************************
if [ $# != 4 ]
then
echo "Usage: $0 "
exit
fi
STR=$1
BEF=$2
AFT=$3
while [ ! -z "$4" ] ; do
echo ========== $4
nawk 'c-->0{print NR ":\t" $0;};$0~s{if(b)for(c=b+1;c>1;c--) print (NR-c + 1) ":\t" r[(NR-c+1)%b];print NR ":\t" $0;c=a}b{r[NR%b]=$0;}' b=$BEF a=$AFT s=$STR $4 | sed "s/^/$4\
/"
shift
done
echo ==========

Took me a while to understand how awk worked and customized the command I found on the net for my own needs.

Wednesday, April 22, 2009

sed and Nix Quotation Confusion

I wanted to use "sed" inside a script to make changes to a text file. The file looked like this:

/*
** Project "OrderCache.7.7.29"
** Hint: deleting everything below the "cause" field will set
** the defaults appropriately for the cause you have chosen.
*/
brief_description = "none";
description = "none";
cause = internal_bug;
test_exempt = true;
test_baseline_exempt = true;
regression_test_exempt = true;
architecture =
[
"unspecified",
];

I wanted to replace the "brief_description" with a value given by the user. So:

#!/bin/csh
set DESC = "$<"

But when I tried to use sed with $DESC:

sed -i 's%brief_description\ \=\ \"none\"\;%brief_description\ \=\ \"$DESC\"\;%g' temp_next.txt

the command would only change "brief_description" as follows:

brief_description = "$DESC";

The reason for this is that the variable has to be inside double quotes in order to get it dereferenced back to the actual value. So the solution is:

sed -i 's%brief_description\ \=\ \"none\"\;%brief_description\ \=\ \"'"$DESC"'\"\;%g' temp_next.txt