Re: Cannot solve complex problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Keith Stemmer" <k.stemmer@xxxxxxxxxxx> schrieb im Newsbeitrag
news:eCrPKv9lIHA.5160@xxxxxxxxxxxxxxxxxxxxxxx

The only thing that scares me is the callback. My idea of a
callback is crashing little beast.
The wrapper encapsulates all the API-Stuff for you.
You have only to define a small Class, which implements
an Interface - and add this Class to the Cnn-Object -
that's all (but look below - at the SourceCode)

I have not been able to find what you told me in your demo.
Can you point me to the right direction, please?
The examples, how to implement userdefined Function-
Interfaces as well as userdefined Collations are in
fUserDefinedFunctions and the Interface-Classes
cMyFunctions, cMyAggFunction and cMyCollations.

And the wrapper as it comes as Binary has already
preimplemented VB-Functions as LCase$, UCase$
and Like, which *deaktivate* (override) the original
"non-unicode-aware" SQLite-Pendants - as said,
as long as you use a Like-Compare over my wrapper,
you work unicode-aware against the real VB6-Like.

For example I need to search recordsets that have
last name 'Ölmer' as well as 'ölmer',
That's covered in the example below.

and maybe even worse for SQLite, it may even be 'de
Ölmer'.
Also covered by the example below, using a userdefined
Collation (without AddrOf-stuff, only a simple to implement
Class).

'****Into a Form
Private Sub Form_Load()
Dim Cnn As cConnection, Rs As cRecordset, SQL$
Set Cnn = New cConnection
Cnn.CreateNewDB 'create a InMemoryDb for our small Demo
'now create a Test-Table T with three simple records:
Cnn.Execute "Create Table T(ID Integer Primary Key, LastName Text)"
Cnn.Execute "Insert Into T Values(1, 'ölmer')"
Cnn.Execute "Insert Into T Values(2, 'Ölmer')"
Cnn.Execute "Insert Into T Values(3, 'Oelmer')"

'and now we make use of the unicode-aware
'function-overrides of the wrapper, they are already
'there (in dhRichClient.dll), nothing to define separately

Debug.Print vbCrLf; "first the caseinsensitive Like:"
SQL = "Select * From T Where LastName Like 'ö%'"
Set Rs = Cnn.OpenRecordset(SQL)
Do Until Rs.EOF
Debug.Print Rs!LastName
Rs.MoveNext
Loop

Debug.Print vbCrLf; "now a caseinsensitive exact-compare:"
SQL = "Select * From T Where LCase$(LastName) = 'ölmer'"
Set Rs = Cnn.OpenRecordset(SQL)
Do Until Rs.EOF
Debug.Print Rs!LastName
Rs.MoveNext
Loop

Debug.Print vbCrLf; "another option for a caseinsensitive compare:"
'the wrapper conatins also an override for SQLites-NoCase-Collation
'to achieve unicode-awareness, which the original doesn't support
SQL = "Select * From T Where (LastName = 'ölmer' Collate NoCase)"
Set Rs = Cnn.OpenRecordset(SQL)
Do Until Rs.EOF
Debug.Print Rs!LastName
Rs.MoveNext
Loop

'*********************
'And now let's enhance the last, collation-based approach
'using our own, userdefined Collation-Definitions.
'We defined two of them in a small Class, which we
'tell the wrapper to use now.
Cnn.AddUserDefinedCollation New cMyCollations

Debug.Print vbCrLf; "another caseinsensitive compare using DE:"
SQL = "Select * From T Where (LastName = 'ölmer' Collate DE)"
Set Rs = Cnn.OpenRecordset(SQL)
Do Until Rs.EOF
Debug.Print Rs!LastName
Rs.MoveNext
Loop

Debug.Print vbCrLf; "and finally the same compare using DE_PhoneBook:"
SQL = "Select * From T Where (LastName = 'ölmer' Collate DE_PhoneBook)"
Set Rs = Cnn.OpenRecordset(SQL)
Do Until Rs.EOF
Debug.Print Rs!LastName
Rs.MoveNext
Loop
End Sub

'***and here comes the small Class, which demonstrates, how
' to Implement the small Interface for userdefinable Collations
' call this Class cMyCollations
Option Explicit

Implements ICollation

Private SC As cStringCompare, LCID_DE As Long, LCID_DE_PhoneBook As Long

'here we define two collation-names as a comma-separated "list"
Private Property Get ICollation_DefinedNames() As String
ICollation_DefinedNames = "DE,DE_Phonebook"
End Property

Private Function ICollation_CallbackCollate(ByVal ZeroBasedNameIndex&, _
S1 As String, S2 As String) As Long
Select Case ZeroBasedNameIndex
'DE (the first entry in the comma-separated list
'in ICollation_DefinedNames)
Case 0
ICollation_CallbackCollate = SC.CompareString(S1, S2, _
cmpIgnoreCase, LCID_DE)

'DE-Phonebook (the second entry in the comma-separated list
'in ICollation_DefinedNames)
Case 1
ICollation_CallbackCollate = SC.CompareString(S1, S2, _
cmpIgnoreCase, LCID_DE_PhoneBook)
End Select
End Function

Private Sub Class_Initialize()
'dhRichClient comes with a ClassWrapper for the CompareString-API
Set SC = New cStringCompare

'let's create and store two different LCIDs at Class-Level
LCID_DE = SC.MakeLCID(German_Germany)
LCID_DE_PhoneBook = SC.MakeLCID(German_Germany, SORT_GERMAN_PHONE_BOOK)
End Sub


Olaf


.



Relevant Pages

  • Re: Getting a ValueError with comtypes
    ... wrapper, but I've been struggling to get it to work. ... I am working with comtypes to interface Microsoft's DirectShow library. ... searches the $PATH to find type libraries. ... COMMETHOD(, HRESULT, 'Pause'), ...
    (comp.lang.python)
  • Re: [patch 05/11] syslets: core code
    ... It was not added by me - it is just a wrapper. ... though) - if you do not want to allocate it explicitly - it is possible ... What exactly do _you_ expect from interface? ... I can work with explicit structure allocation/deallocation/setup - ...
    (Linux-Kernel)
  • RE: Running public IPs inside an RFC 1597 network
    ... > I'm running a typical Class C RFC 1597 network in my lab. ... know or care if we humans designate a subnet as public or private. ... is the absolute most general route there is for a machine. ... In a correctly configured system when you define an interface, ...
    (freebsd-questions)
  • Re: modular programming in Forth
    ... "The public definitions constitute the ... interface to codeexternal to the module" ... you can tinker at will with the source for the private words, ... to fixing a pesky bug. ...
    (comp.lang.forth)
  • Re: compilers
    ... I do it on my free time, which isn't really that often now. ... an MS.NET interface will be ... This statement defines a wrapper to call a non-.NET DLL (QMClient.dll ... with the assumption that much of the core ...
    (comp.databases.pick)