Python, Oracle and LOB objects
Recently, one of these tasks involved querying a table with a LOB column that stores XML strings. So the challenge was to read the LOB column and parse as string to dump the records to file.
My setup is Python 2.7 with the CxOracle 5.0.4 library. The first try I ran into the “LOB variable no longer valid after subsequent fetch” exception. According to the documentation this is because internally, Oracle uses LOB locators which are allocated based on the cursor array size. Thus, it is important that the data in the LOB object be manipulated before another internal fetch takes place. It also states that the safest way to do this is to use the cursor as an iterator.
Well, that’s all very nice, but I wouldn’t hang a cursor on a whole table, fetching the records one-by-one and processing the whole XML before going for another fetch. That’s not advisable on an OLTP database.
My solution and suggestion to other python users is to perform a two step fetch process:
- Fetch all relevant primary keys from the table;
- Fetch the LOB column one-by-one using the PK list from the previous step.
def executaQueryLOB(txtQuery):
import cx_Oracle
orcl = cx_Oracle.connect('yourConnectioString')
curs = orcl.cursor()
curs.execute(txtQuery)
result=curs.fetchall()
strLOB=result[0][0].read()
orcl.close()
return strLOB
HTH.
Cartão de Cidadão – APIs de Desenvolvimento
Esta aposta confirma-se com a publicação no Diário da República da Resolução do Conselho de Ministros nº.12/2012, de 7 de Fevereiro de 2012 que aprova o plano global estratégico de racionalização e redução de custos com as TIC na Administração Pública, apresentado pelo Grupo de Projeto para as Tecnologias de Informação e Comunicação (GPTIC).
Posto isto, é relevante fazer um levantamento do que existe actualmente que posa servir de base e acelerar o desenvolvimento da integrações do Cartão de Cidadão nas aplicações.
Numa pesquisa pouco exausta na Internet, aparecem os seguintes projectos:
O middlware do cartão é sempre necessário, de modo que na realidade apenas enumerei um projecto de terceiros que age com um wrapper .NET que expõe a API de interacção com o smart card.
Fica aqui o desafio de colocarem nos comentário a a esta mensagem algum projecto que conheçam ou usem e não esteja entre os referidos.
Windows Monitoring – Codeplex
This project is meant to provide programmers with a set of reusable classes, gathered into one assembly, to develop custom system monitoring consoles for windows server systems.
The base set provides classes with methods to check:
- Network ping
- HTTP server running
- FTP server running
- Disk space on system hard drive
- Database availability
I took the dust off the Codeplex account, logged in using Visual Studio 2010 together with Team Explorer and migrated the code from .NET 2.0 onto 4.0.
The update projects and source code can be browsed and downloaded. If you don’t have Visual Studio, but some other IDE, you can download the assembly on the recommended release and use the tester source code as a usage example.
Happy coding!
Manually placing pending OneNote updates to SkyDrive
On a careless fashion, I kept taking notes from tasks and e-mails and the pending updates stacked up. Final picture: ended up with a really stuffed set of notes missing from the online service.
No matter how I tried to start the process, the merge between the notes always failed on the Windows Live ID login step.
The web browser view on Skydrive presents the notebook as a single item, but OneNote stores the different sections of a notebook on separate “.one” files. For the whole notebook there is a table of contents “.onetoc2” file. So the potential solution was to replace the Skydrive files with the local backup files that had all the recent updates.
The solution wasn’t feasible on the Web browser Skydrive functionality, as it presents the notebook as a single item. It was a four step process:
- Get Skydrive to open on Windows Explorer.
- Backup your online notebook to a local folder and open it.
- Open the files from the local OneNote backup folder.
- Copy the local files over the old ones.
Backup your online copy to a local folder. Open the notebook on OneNote.
To get the local backup of your skydrive files, it should be on a folder path like “C:\Users\[Your user name]\AppData\Local\Microsoft\OneNote\14.0\Backup”. Replace [your user name] with the real deal. Open the notebook on OneNote.
With both versions of the notebook open, check if there are missing notes and copy/paste them into the copy with the least updates missing.
Finally, copy the whole “.one” files from the updated version, replacing the ones on Skydrive, using Windows Explorer.
HTH.
Dados.gov - transparência e a reutilização da informação do sector público
Citando o próprio site, o Dados.gov é um portal que tem como função publicar e agregar a informação produzida pela Administração Pública em formatos abertos que possam ser lidos e reutilizados por qualquer cidadão. O objectivo fundamental da criação deste portal visa facilitar o acesso à informação pública, promover a transparência da Administração Pública e ajudar na criação de serviços públicos electrónicos pela sociedade civil.
Já existe uma iniciativa global de transparência e reutilização dos dados que podem ser acompanhadas no portal OPEN! Government Data. A par da iniciativa portuguesa, já existem iniciativas relevantes, previamente lançadas por outros países:
O particular interesse da iniciativa portuguesa de dados abertos, é que propõe facilitar imenso a criação de um próprio ecossistema de satélites de informação, utilizando as suas origens de dados. Nesse sentido, disponibiliza:
- Um catálogo de dados: estão disponíveis todos os conjuntos de dados partilhados por instituições da Administração Pública
- Serviços de obtenção de Datasets através de protocolos REST com XML em padrão AtomPub (OData), JSON e outros.
- Tutoriais para programadores em .NET e Java.
Existe inclusivamente um inventário das aplicações já desenvolvidas por terceiros com base nas origens de dados do Dados.gov.
Este portal vai de certeza passar a ser a vítima preferida para alguns ensaios de programação.
Deixo um vídeo elucidativo dos projetos Open Government Data:
#opendata from Open Knowledge Foundation on Vimeo.
A implementação das boas práticas ITIL na Administração Pública: um estudo de caso
Há coisa de cinco anos, o Instituto onde trabalho submeteu-se a um processo de adopção do ITIL. Foi um trabalho estruturante de adopção de metodologias, criação de processos e auto-estudo, com uma prova de certificação para cada colaborador.
Numa pesquisa em nada relacionada com o tema, deparei-me com uma dissertação de mestrado, acerca desta adopção do ITIL por parte de uma entidade da Administração Pública, escrita pelo então diretor do departamento de sistemas.
Por ser um caso interessante onde a racionalização dos processos se traduz numa efetiva melhoria no serviço aos utilizadores e cidadãos, deixo aqui o endereço onde podem descarregar o documento:
A implementação das boas práticas ITIL na Administração Pública: um estudo de caso
Boas leituras!
Android: Restore FTM after clockworkMod
Recovering with a stock ROM from the carrier was not an option because it involved restoring the FTM startup, which should not be necessary because ClockworkMod was working fine. So, in spite of this post’s title, I’'ll explain how to recover your Android back into a custom ROM without the need to overwrite ClockworkMod.
My personal feeling about the scenario is that something got really messed up on the system or boot partitions of the SD card. And turned out in the end I was right.
The first challenge was to how I was going to copy the .ZIP file with the custom ROM to the SD card if I was unable to boot the system. It’s a simple mount/unmount functionality on ClockworkMod:
- Connect the phone to a computer.
- Turn the phone on with volume down and power held.
- In clockworkmod go to “mounts and storage” and select mount USB storage.
- Copy your custom ROM to the SD card.
- Unmount USB Storage
- Go to “mounts and storage”
- Format boot.
- Format system.
- Format data.
- Format cache.
- Finally format sd-ext.
- Go to “install zip from SD card”
- Install the ROM you copied previously.
- Restart your phone when it is finished.
HTH.