Consciousness

CLOB and PDO, specifically Oracle

Posted in Oracle, Programming, databases by Personalife on the April 30th, 2008

So, my new job has me working with Oracle which is in my book, a way different beast compared to mySQL. Everything I know about databases from mySQL basically had to be re-tooled for Oracle.

I spent around 3 hours trying to figure out how to work in a set of prepared statements (one of which returned a value) in PHP PDO, and thought I might share how I did this.

Okay, so I have one stored procedure and one function.

PROCEDURE RETURN_CLOB(:CLOB_ID, :CLOB_OUT IN CLOB) — All this does was search a table with key/ CLOB value pairs. It basically selected a row with the :CLOB_ID, and :CLOB_OUT returned the CLOB value.

FUNCTION CONVERT_CLOB_TO_VARCHAR2(:CLOB_OUT IN CLOB) RETURN VARCHAR2 — this was a function definition that took in the :CLOB_OUT from RETURN_CLOB and spit it out as a VARCHAR2

Note that I did not write these two procedures, it’s something out of a package I used at work, but was having trouble trying to get them to work in PDO.

I’m using PHP Propel 1.3, but you can easily rewrite this in standard PDO calls, since the $con object is actually a combination of the PDO class and PDO Statement class.
Here’s the code:

$con = Propel::getConnection(‘…’); //All this does is just use PDO to create a connection
/*

The call below is the same as PDOStatement::prepare(). I’ve condensed the following into one line:

DECLARE

CLOB_Output CLOB;

BEGIN

PackageName.RETURN_CLOB( :Clob_Id, CLOB_Output );

:Str := PackageName.CONVERT_CLOB_TO_VARCHAR2( CLOB_Output );

END;

//So the declare part is to define an internal variable in Oracle, which I’ve named CLOB_Output. It is of type CLOB. The Begin … End block processes the statements in one container.

1. Return_CLOB returns the CLOB data in CLOB_Output

2. Call CONVERT_BLOB_TO_VARCHAR2 with CLOB_Output

3. The converted CLOB is returned into :Str
*/
$stmt = $con->prepare(“DECLARE CLOB_Output CLOB; BEGIN PackageName.RETURN_CLOB( :Clob_Id, CLOB_Output ); :Str := PackageName.CONVERT_CLOB_TO_VARCHAR2( CLOB_Output ); END;”);

$m = “”;

$stmt->bindValue(‘:Clob_Id’, ‘Clob_Id_goes_here’, PDO::PARAM_INT);

$stmt->bindParam(‘:Str’, $m, PDO::PARAM_STR, 32767); //replace 32767 with the size of the VARCHAR2 that you are returning from CONVERT_BLOB_TO_VARCHAR2

$stmt->execute();
//$m now contains the CLOB as a VARCHAR2!
Phew! Anyways, I’m going to say that Propel 1.3 isn’t ready for Oracle yet, and neither is PHP_PDO for Oracle. There’s too many hassles and tricks I had to use to do the things I needed in Oracle, and I’m going to recommend people continue to use the OCI8 extension.

Dynamic Programming: Needleman/Wunsch Tutorial

Posted in Bioinformatics by Personalife on the April 8th, 2008

Needleman/Wunsch:

http://www.avatar.se/molbioinfo2001/dynprog/dynamic.html

I found that to be pretty useful in my bioinformatics class. Used to find possible best alignment between two sequences.

I haven’t found any useful guides on doing the Nussinov. What pisses me off the most is that 99% of the information on Nussinov uses the same example pulled from Durbin et al, which doesn’t really include any proper information on how to perform traceback step-by-step.

Update (12/27/08): One of my Stanford friends gave me a link to his CS262 lecture slides for the algorithm:

http://ai.stanford.edu/~serafim/CS262_2006/Slides/CS262_2006_Lecture3.ppt

A Real Fictional Story 0:1

Posted in Autobiography, Favorites by Personalife on the April 8th, 2008

Note: This is a draft of what I might consider the beginnings of my autobiography. It may be updated at any time, indicated by version numbers.

My fondest childhood memories mainly involved video games. From the age of four or five, I found myself closely acquainted with a Nintendo Entertainment System (commonly referred to as the NES), where my first video game was Super Mario Bros. I dearly wanted to know how to play the game so badly that I asked my parents to read the instruction manual to me.

“Learn to read it yourself,” one of them said.

And so, while trying to gain an initial understanding of Mario Bros. gameplay mechanics, I also found myself making friends with the Hooked on Phonics cassette tape program. By the time I was in kindergarten, I was reading books to kids in the class, and was placed in a second grade reading program.

Despite this fact, I was never considered a ‘genius’ at school, and an actual IQ test performed in my late teens would demonstrate that. However, if there was one word to describe my life, it would be “exceptional”. Throughout my childhood leading up to my present, I would find out that I held “powers of exception”, as noted by my friends.

***

My elementary school days (from kindergarten to 8th grade) were quite imaginative – heavily influenced by video games and Saturday morning cartoons. Morning recess was spent with friends pretending that we were individual characters from the X-Men, doing battle with each other on the field every day, while lunchtimes were reserved to practicing our german dodgeball skills, which was the most popular sport at school during my years.

My parents immigrated from Thailand in the late 70s, after graduating from their masters programs in business administration and literature, respectively from Punjab University in India. My mother was a temporary English teacher at a university in San Francisco, California, but both eventually went to work as a waiter and waitress at the Hilton Hotel which was near the San Francisco Airport. Eventually, during this time, they would come to own their own restaurant in Pacifica, which had a tiny apartment attached, where I would spend my childhood and teenage years being a dishwasher, taking orders, and running the register while my two siblings (brother and sister), would go out and play with their friends. This particular situation would later bring a lot of problems in my teenage and adult years.

Like most asian parents, they were in the beginning quite typical of how they were to raise us, and it was commonly frequent to receive lashings for readings not performed, or grades that were not ‘A’s. From kindergarten to 4th grade, I would never receive anything close to straight As, but that eventually changed when my parents spoiled me with incentives where I could have anything I wanted if I obtained straight As at the end of each quarter.
***

Video games are heavy in my life, and as mentioned before, my childhood. Everything about video games brought about so much curiosity, my parents had trouble explaining or answering questions on how video games were made. Instead, I was introduced to two males, who would become extremely influential in my later developments as a programmer and a thinker. Also, they would be both my first exposure to trans-genderism and homosexuality in my teenage and adult years.

(Despite my interactions with them throughout the years, I would like to note that my orientation remains heterosexual.)

The World of Computing

These two males, Larry and Grave, were the seeds that brought my interest into computing. My first computer was a Commodore PET, but being five or six at the time, I was literally scared of the noises it would generate when trying to perform operations, and the methodology of running programs from a cassette tape was extremely foreign to my dad and I, that it was immediately discarded for an IBM XT/AT, which would become the primary platform I would learn from for many years.

(To be continued..)

Context-Free Grammar Tutorials

Posted in Finite Automata, Lingustics by Personalife on the April 8th, 2008

So far, I’ve found these tutorials to be one of the best in terms of learning Context-Free Grammars:

http://www.cis.uoguelph.ca/~sawada/4620/notes/push-1×2.pdf

http://www.coli.uni-saarland.de/~kris/nlp-with-prolog/html/node37.html

Tutorial on removing lambda and unit productions (halfway of the tutorial)

http://www.cset.oit.edu/~yangs/CST229/Lecture/6_grammarforms.pdf

Another good one that includes Chomsky Normal Form:

http://www.cs.colostate.edu/~cs301/RestrictedAccess/Slides/301lecture10.pdf

Chomsky Normal Form:

http://www.cs.umbc.edu/~squire/cs451_l16.html

This one has nice color-coded step by step at the end:
http://www.ugrad.cs.ubc.ca/~cs421/notes/10.13/slides.pdf

Don’t forget JFlap also has a nice Chomsky converter.

Greibach Normal Form:

www.cs.wpi.edu/~kal/courses/cs503/module7/grahneclass9.ppt

A thing to note about Greibach is that it’s like an s-grammar, but rather than being forced to just a maximum of two variables, it can have an unlimited amount. So basically, in an s-grammar, you can have a form with:

S->aA (one letter and one variable at most)

vs the Greibach form:

S->aAB (Second variable or even more is okay)

Pushdown Automata

 www.cs.rpi.edu/~drinep/modcomp/class10.ppt

Yay, midterms. I need to write more in here. There’s been lots of changes in my life recently, one of them being that I’ll be dropping out of school shortly to pursue a product management position with my current employer.

On a side note, I recently made the connection between OS Schedulers/Process management from my Understanding Operating Systems class with how product roadmaps and development might be built. It’s not a new idea I think, but to me, I thought it was cool when I realized it.

Powered by WordPress .::. Designed by SiteGround Web Hosting