Friday, June 26, 2009

4GL comma split function

not really.. but if you want to iterate over a delimited string via 4gl, you can do the following:

(parse_str function adapted from http://www.tek-tips.com/faqs.cfm?fid=2364 )


# This function searches string for an instance of char_delim
# starting at position cnt and returns the string ending at the next
# char_delim or the end of string
######################################################################
function parse_str(char_delim, cnt, string)
######################################################################
define
char_delim CHAR(1), # character delimiter
cnt SMALLINT, # postion in string to start counting
string CHAR(300), # string to search
ret_string CHAR(40), # string returned
i, # index
x, # counter
string_len SMALLINT # string length

LET string_len = LENGTH(string)

IF string_len = 0 # got a null string
THEN
RETURN "",0
END IF

IF string[cnt] = char_delim
THEN
LET cnt = cnt + 1 # get off the delimiter
END IF
IF cnt > string_len
THEN # return when the end of the string is reached
RETURN "",0
END IF

LET x = 1
FOR i = cnt TO string_len
IF string[i] = char_delim
THEN
EXIT FOR
END IF
LET ret_string[x] = string[i] # save a character
LET x = x + 1
END FOR

return ret_string, i # return the positon ended
end function

function split(f_orig)
define f_orig,f_str char(100), x, f_pos smallint
let x = length(f_orig)
let f_pos = 1
while (f_pos > 0 and f_pos < x)
call parse_str(",",f_pos,f_orig) returning f_str, f_pos
display f_str, f_pos
end while
end function

main
call split("some,comma,delimited,string")
end main

Aubit4GL: connecting to mysql and informix concurrently

Since database connections seems to be compile time, and you have to set A4GL_SQLTYPE in order to compile against database X - I wonder how you can open concurrent connections.. I cannot find any documentation on how to do this - but according to http://aubit4gl.sourceforge.net/aubit4gldoc/manual/html/features_summary.html it maybe that you have to use ODBC connections to each instead of native??

It seems that "open session" and "use session" can be used to dynamically switch at runtime. But compile time seems to be the kicker.. especially if you use "define x like table.column" in 4gl, unless it allows "define x like db.table.column" or searches both databases.

Thursday, June 25, 2009

Aubit4GL: mysql connection specification

Since this is not well documented on Aubit4gl site, posting here:

To connect to mysql database:

  1. Make sure your mysql server is not bound to localhost - even local connections are via hostname
  2. Make sure you can connect to mysql server.. grant at least select privs using "grant select on db.* to 'test'@'hostname' identified by 'test';" NOTE: localhost privs are not enough - connection thru hostname.
  3. Do "export MYSQL_SERVER=hostname"
  4. Set/export the following environment variables:
A4GL_SQLUID=test #whatever connection user is
A4GL_SQLPWD=test #whatever connection password is
A4GL_LEXDIALECT=INFORMIX
A4GL_LEXTYPE=C
A4GL_SQLTYPE=mysql

And now take the simple.4gl program:

database test # of whatever your database name is

main
display "Hello World"
end main

Compile with : aubit 4glpc simple.4gl -o simple.4ae

If it compiles - database connection is ok!

Thanks to Mike's comment below - using .aubit4gl.acl to store database:user:pw DOES work.. just be sure to "unset A4GL_SQLUID" and "unset A4GL_SQLPWD".

Logitech Quickcam Pro 9000 on ubuntu hardy - no go

On initial plugin:

[ 102.851571] usb 3-1: new full speed USB device using uhci_hcd and address 2
[ 44.040462] usb 3-1: device descriptor read/64, error -71
[ 102.933128] usb 3-1: device descriptor read/64, error -71
[ 102.939599] usb 3-1: new full speed USB device using uhci_hcd and address 3
[ 102.945009] usb 3-1: device descriptor read/64, error -71
[ 102.970417] usb 3-1: device descriptor read/64, error -71
[ 102.983105] usb 3-1: new full speed USB device using uhci_hcd and address 4
[ 103.020497] usb 3-1: device not accepting address 4, error -71
[ 103.025529] usb 3-1: new full speed USB device using uhci_hcd and address 5
[ 103.060941] usb 3-1: device not accepting address 5, error -71
[ 116.499098] usb 5-5: new high speed USB device using ehci_hcd and address 5
[ 116.627482] usb 5-5: configuration #1 chosen from 1 choice

and

lsusb -d 046d:0990 -v | grep bcdDevice
bcdDevice 0.08
which according to http://www.quickcamteam.net/documentation/faq/how-many-versions-of-the-quickcam-pro-9000-are-there says its third generation with buggy firmware.

If I launch cheese - system hangs completely.

According to http://linux-uvc.berlios.de/, linux 2.6.26 includes linux uvc driver natively.. but hardy is 2.6.24.

Downloaded the driver from http://linuxtv.org/hg/~pinchartl/uvcvideo/ (gz link) and then..

tar zxvf uvcvideo-bff77ec33116.tar.gz
cd uvcvideo-bff77ec33116/
make # and go have a coffee
sudo make install
reboot
dmesg now shows:

[ 105.937744] usb 5-5: new high speed USB device using ehci_hcd and address 3
[ 106.197507] usb 5-5: configuration #1 chosen from 1 choice
[ 107.127908] Linux video capture interface: v2.00
[ 107.135021] usbcore: registered new interface driver snd-usb-audio
[ 45.915452] uvcvideo: Found UVC 1.00 device (046d:0990)
[ 45.932166] input: UVC Camera (046d:0990) as /devices/pci0000:00/0000:00:1d.7/usb5/5-5/5-5:1.0/input/input10
[ 45.962220] usbcore: registered new interface driver uvcvideo
[ 45.962226] USB Video Class driver (v0.1.0)

cheese shows no output
skype neither
dmesg now shows

[ 177.592621] uvcvideo: Failed to set UVC probe control : -110 (exp. 26).
[ 177.976920] uvcvideo: Failed to set UVC probe control : -110 (exp. 26).
[ 178.401788] uvcvideo: Failed to set UVC probe control : -110 (exp. 26).
[ 178.807251] uvcvideo: Failed to set UVC probe control : -110 (exp. 26).
[ 179.193500] uvcvideo: Failed to set UVC probe control : -110 (exp. 26).
[ 179.743456] uvcvideo: Failed to set UVC probe control : -110 (exp. 26).
[ 180.154183] uvcvideo: Failed to set UVC probe control : -110 (exp. 26).
[ 180.655020] uvcvideo: Failed to set UVC probe control : -110 (exp. 26).

skype reports

Skype V4L2: Could not find a suitable capture format
Skype V4L2: Could not find a suitable capture format

Aborting effort for now..

Tuesday, June 23, 2009

mysqldump to informix DS

Problem: Need to access mysql 5.0 data from 4js BDL (I4gl)

Solution attempts:
  1. generate 4js dynamic VM with mysql support.. no mysql 5.0 support (only 4.x) and not forward compatible
  2. try aubit4gl with mysql support.. no go.. see this
  3. call script to unload mysql table and then load into informix
On solution attempt 3 - this proved more difficult than I first imagined.

I've been spoiled with Informix's very easy "unload to". Mysql simply has no equivalent. There is the "SELECT INTO OUTFILE", but (1) you need to "grant file on *.* to 'user'@'whateverhost'" (besides select permission of course), and (2) can be run from a remote host, but the output file is local to the mysql server instance.. and while you can use NFS, its a pain.

Also there is mysqldump - which I thought might do it.. but alas, if you use the --tab option it uses "SELECT INTO OUTFILE" internally anyway - plus you need to "grant lock tables on db.* to 'user'@'whateverhost'".

Ok - so had to revise my strategy - since I am running this script on remote host... this generates ansi "insert" statements that I will try to execute against informix:

mysqldump -h mysqlhost -usomeuser -psomepassword --compatible=ansi --no-create-info --compact dbname tablename > x.sql

Kinda works.. doesn't like text fields (clob datatype in informix).. and date formating could be an issue (easily fixed with informix DBDATE environment variable).. but certainly not as easy as I imagined.

BladeCenter S vitals via SNMP - installing MIBs

Thanks to this post:

http://blog.barfoo.org/2009/02/10/monitoring-the-ibm-bladecenter-chassis-with-nagios/

I was able to use SNMP to get all kinds of info from my BladeCenter S - and specifically have it monitored with nagios. The original poster stated that the OIDs weren't documented anywhere.. but that is what the mib file is.. you just need to install it..

Here is how to install the MIBs from the IBM firmware (mmblade.mib) on ubunutu (requires snmp package):

copy mmblade.mib (contained in the firmware download) to /usr/share/snmp/mibs/BLADE-MIB.txt

(if you want alerts.. copy mmalerts.mib to /usr/share/snmp/mibs/BLADESPPALT-MIB.txt)

You now have access to over 10,000 settings.. you can get a complete list by doing:

snmpwalk -v1 -c public -Of ipaddress-of-bladecenterS -m BLADE-MID enterprises.ibm


and then for example, to find the front panel temperature:

snmpwalk -v1 -c public -Of ipaddress-of-bladecenterS -m BLADE-MIB enterprises.ibm.ibmAgents.netfinitySupportProcessorAgent.
bladeCenterSnmpMIB.monitors.temperature.ambientTemp.
frontPanelTemp.0


which, although quite verbose.. is more human readable than
snmpwalk -v1 -c public -Of ipaddress-of-bladecenterS
.1.3.6.1.4.1.2.3.51.2.2.1.5.1.0



Monday, June 22, 2009

Aubit4GL and libmysqld

Had a frustrating time trying to build aubit4gl on ubuntu with mysql support.

/usr/bin/ld: /usr/lib/mysql/libmysqld.a(net_serv.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/lib/mysql/libmysqld.a: could not read symbols: Bad value


This is from libmysqlclient15-dev package. Turns out its not even an ubuntu issue.. its actual mysql bug:

http://bugs.mysql.com/bug.php?id=39288

I did see somewhere that it was fixed in libmysqlclient16-dev - which is not available in hardy (8.04) which I need.

I stumbled upon this link and was able to build a relocatable libmysqld.. but then I ran it this:

gcc -shared -L/lib -o /opt/aubit4gl/src/plugins-1.10RC_62/libSQL_mysqldb.so db-mysql.o -L/usr/local/lib -L/usr/local/mysql -L/usr/lib/mysql -L/usr/lib -L/opt/aubit4gl/src/lib -lmysqld -laubit4gl-1.10RC_62 -Wl,-Bsymbolic-functions -L/usr/lib/mysql -lmysqld -lwrap -lrt
/usr/bin/ld: cannot find -lwrap
even though libwrap is in /lib .. arrrg ok.. so I did the following:

cd lib/libsql/mysql
gcc -shared -L/lib -o /opt/aubit4gl/src/plugins-1.10RC_62/libSQL_mysqldb.so db-mysql.o -L/usr/local/lib -L/usr/local/mysql -L/usr/lib/mysql -L/usr/lib -L/opt/aubit4gl/src/lib -lmysqld -laubit4gl-1.10RC_62 -Wl,-Bsymbolic-functions -L/usr/lib/mysql -lmysqld
cd ../../..
make
(ie. I just removed -lwrap and -lrt and it went ok) and proceeded to compile the remainder of aubit4gl. Now to test against mysql