Os Cursores Compartilhados

Ando com meu tempo meio oprimido. Tentando me dividir entre meus estudos, coisas da casa e escrever aqui. Meus outros dois blogs estão praticamente entregues as traças. Meus dois companheiros de blogagem (um em cada outro blog) conseguem ainda escreverem menos que eu.
Então, resolvi escrever sobre um problema de banco de dados bizarro que tive certa vez. Tudo levava a crer que era algo relacionado a código fonte, frames, delphi e tal. "QR_Faturas: Type mismatch for filed 'data_emiss', expecting: String actual: Memo".
Notamos que o erro ocorria sempre que abria uma tela cujo grid tinha algum campo que levava conversão de TO_CHAR, ou TO_DATE. É frame, não é... O mesmo executável funciona em outra base com os mesmos dados... What a hell!?!?!?!
Lembrei que há uns 3 anos atrás tivemos um problema semelhante e realmente era um parâmetro de banco que causava toda essa confusão: CURSOR_SHARING. Esse parâmetro determina como uma instrução SQL irá compartilhar o cursor na memória:
FORCE: Faz com que instruções com pequenas diferenças na escrita compartilhem do mesmo cursor;
SIMILAR: Faz com que instruções com pequenas diferenças na escrita compartilhem do mesmo cursor, a menos que a variável afete o sentido da escrita ou o grau de otimização da sua execução.
EXACT: Só haverá o compartilhamento do cursor se, e somente se, a escrita da instrução for idêntica, mudando apenas a variável passada.
O valor padrão é EXACT, mas por algum motivo alguém leu em algum lugar que colocando como SIMILAR daria uma incrementada na performance. É até verdade, se o BDE conseguisse interpretar corretamente algumas instruções compartilhadas. No caso de datas convertidas para texto, usando o TO_CHAR, concatenadas com alguma outra coisa, por algum motivo o campo é interpretado como MEMO, retornando erro acima no componente que estava esperando uma String.
Então quero deixar bem claro esse aviso: O sistema WpdHosp, por enquanto, ainda não funciona com o CURSOR_SHARING diferente de EXACT. Não adianta aplicar patch do Oracle ou fazer upgrade no banco. É questão de DLL e BDE. Talvez com o Delphi 10 consigamos contornar esse problema...



I had been having my time a little underdog. Trying to share it between my studies, things for write and house stuffs. My other two blogs are piratically dammed to the forgetfulness. My two blog partners (one for each of the blogs) can write even less then me.
So, today I resolved to write about a bizarre database problem that I had once. When you see the problem for the first time you just guess that's related to program code, frames, delphi and all. "QR_Bills: Type mismatch for filed 'emiss_date', expecting: String actual: Memo".
We had noted that the error always happened when the user opened some function where the screen had in its grid some field with a data conversion as TO_CHAR or TO_DATE. It's the frame, Isn't the frame... But the same executable worked on another database with the same data... So, what a hell?!?!?!
Then I remembered three years ago, when we had a similar problem and was really a database parameter which cause all this confusion: CURSOR_SHARING. This parameter determines when and how a SQL statement will share a cursor at the memory:
FORCE: Forces statements that may differ in some literals, but are otherwise identical, to share a cursor, unless the literals affect the meaning of the statement.
SIMILAR: Causes statements that may differ in some literals, but are otherwise identical, to share a cursor, unless the literals affect either the meaning of the statement or the degree to which the plan is optimized.
EXACT: Only allows statements with identical text to share the same cursor.
The default is EXACT, but for some reason somebody read that the SIMILAR value would increase the performance. And it's true, if the BDE would correctly interpret the shared statements. In this case, date converted to text using the TO_CHAR function, concatenated with something else, for some reason this field will be interpreted as a MEMO field, returning the error above on the component which was expecting a String.
Let me be more clear: the WpdHosp system, for now, still didn't work with the CURSOR_SHARING with a value different from EXACT. Not worth to apply Oracle patch or doing some database upgrade. The question is the BDE and the DLL used by it. Maybe with the Delphi 10 we can make it work around the problem...

Comentários

  1. Guzma, I want that bloody sock thrown out. It's funny how much you database reminds me of brain function.

    ResponderExcluir

Postar um comentário

Postagens mais visitadas deste blog

CPF pra Estelionatário Ver!

Data Protector Cannot connect to the SCM (Service Control Manager)

Puff Power Daneryes