[Gambas-user] search over the gridview and not to the database and refill grid its possible?

2017-06-17 Thread PICCORO McKAY Lenz
as subject said: search over the gridview event to the database and refill
grid its possible?

i have a gridview object filled with data from the db, note: column names
are autodetected.

its there any way to search over gridview data and filter the results in
gridview or there-s some object with that behaviour?

Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] [Gambas Bug Tracker] Bug #1113: ODBC driver problem: driver connects but does not exec query

2017-06-17 Thread bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1113=L21haW4-

Comment #10 by PICCORO LENZ MCKAY:

ok, i understand sorry for the noise, its just that i tested many odbc module 
drivers and tested that..

in other words, i tested the condition with sqlite and i confirmed does not 
work..



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] [Gambas Bug Tracker] Bug #1113: ODBC driver problem: driver connects but does not exec query

2017-06-17 Thread bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1113=L21haW4-

Comment #9 by zxMarce:

Piccoro,

As I already told you more than once, ODBC will return the row count thanks to 
the patch I already made given a couple of conditions that depend on the 
low-level driver being correctly configured.

The conditions are:
A- The driver supports ODBC's SQLFetchScroll() call (this is not a driver 
config, but a driver feature), and
B- The driver is configured in such a way that it supports the 
SQL_ATTR_CURSOR_SCROLLABLE flag.

My patch uses condition B to use three times the call in point A in this way:
1- Remember the current row for later getting back to it.
2- Seek up to the first row in the rowset (using SQLFetchScroll)
3- Get the first row's index (firstRecNo)
4- Seek down to the last row in the rowset (using SQLFetchScroll)
5- Get the last row's index (lastRecNo)
6- Seek back to wherever we were at in step 1 (using SQLFetchScroll)
7- Return (lastRecNo - firstRecNo + 1), AKA "Record Count".

For some combinations of driver protocol and MSSQL versions (speaking FreeTDS 
against MSSQL here), I found out that condition B was not met, so I could not 
get a record count.
But for some other -documented- protocol and server combinations the call 
succeeded. The same happens with Firebird, for example.
I never tested it with SQLite3 yet. But I explained this point to you several 
times now. Will not do it again, and this contaminates this particular bug 
report.
zxMare.



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Help needed from regexp gurus

2017-06-17 Thread Jussi Lahtinen
Oh, sorry... this way of course:

  Dim sStr As String = "abc. def!!! ghi?   jkl:  (mno)"
  Dim sWords As String[]

  sWords = Split(sStr, " .!?:()", "", True) ''Expand as you will.

  For ii = 0 To sWords.Max
   Print sWords[ii]
  Next



Jussi

On Sun, Jun 18, 2017 at 6:29 AM, Jussi Lahtinen 
wrote:

> It's not problem.
>
>   Dim sStr As String = "abc. def!!! ghi?   jkl:  (mno)"
>   Dim sWords As String[]
>
>   sWords = Split(sStr, " .!?:()") '' Exapand as you will.
>
>   ii = 0
>   Do
> If sWords[ii] = "" Then
>   sWords.Remove(ii)
> Else
>   Inc ii
> Endif
>   Loop Until ii > sWords.Max
>
>   For ii = 0 To sWords.Max
>Print sWords[ii]
>   Next
>
>
> Jussi
>
>
> On Sun, Jun 18, 2017 at 4:53 AM, Fernando Cabral <
> fernandojosecab...@gmail.com> wrote:
>
>> Jussi, what you suggest will not work. You have presumed the only
>> separator is a single space.
>> This is not the case. Between any two words you can have any non-alpha
>> character in any number.
>> It could be, for instance, "abc. def!!! ghi?   jkl:  (mno)" and so
>> forth.
>> This means, the definition of word is "any sequence of alphabetic
>> characters followed by any sequence of non-alphabetic.
>>
>> That's why your suggestion does not apply.
>>
>> - fernando
>>
>> 2017-06-17 21:21 GMT-03:00 Jussi Lahtinen :
>>
>>> I think I would do something like:
>>>
>>>   Dim ii As Integer
>>>   Dim sStr As String = "abc defg hijkl"
>>>   Dim sWords As String[]
>>>
>>>   sWords = Split(sStr, " ")
>>>
>>>   For ii = 0 To 2
>>>Print sWords[ii]
>>>   Next
>>>
>>>
>>>
>>>
>>> Jussi
>>>
>>> On Sun, Jun 18, 2017 at 2:57 AM, Fernando Cabral <
>>> fernandojosecab...@gmail.com> wrote:
>>>
 Tobi

 One more thing about the way I wish it could work (I remember having
 done
 this in C perhaps 30 years ago). The pseudo-code bellow is pretty
 schematic, but I think it will clarify the issue.

 Let p and l be arrays of integers and s be the string "abc defg hijkl"

 So, after traversing the string we would have the following result:
 p[0] = offset of "a" (0)
 l[0] = length of "abc" (3)
 p[1] = offset of "d" (4)
 l[1] = lenght of "defg" (4)
 p[2] = offset of "h" (9)
 l[2] = lenght of "hijkl" (5).

 After this, each word could be retrieved in the following manner:

 for i = 0 to 2
 print mid(s, p[i], l[i])
 next

 I think this would be the most efficient way to do it. But I can't find
 how
 to do it in Gambas using Regex.

 Regards

 - fernando


 2017-06-17 18:06 GMT-03:00 Tobias Boege :

 > On Sat, 17 Jun 2017, Fernando Cabral wrote:
 > > Still beating my head against the wall due to my lack of knowledge
 about
 > > the PCRE methods and properties... Because of this, I have
 progressed not
 > > only very slowly but also -- I fell -- in a very inelegant way. So
 > perhaps
 > > you guys who are more acquainted with PCRE might be able to hint me
 on a
 > > better solution.
 > >
 > > I want to search a long string that can contain a sentence, a
 paragraph
 > or
 > > even a full text. I wanna find and isolate every word it contains.
 A word
 > > is defined as any sequence of alphabetic characters followed by a
 > > non-alphatetic character.
 > >
 >
 > The Mathematician in me can't resist to point this out: you hopefully
 > wanted
 > to define "word in a string" as "a *longest* sequence of alphabetic
 > characters
 > followed by a non-alphabetic character (or the end of the string)".
 Using
 > your
 > definition above, the words in "abc:" would be "c", "bc" and "abc",
 whereas
 > you probably only wanted "abc" (the longest of those).
 >
 > > The sample code bellow does work, but I don't feel it is as elegant
 and
 > as
 > > fast as it could and should be.  Especially the way I am traversing
 the
 > > string from the beginning to the end. It looks awkward and slow.
 There
 > must
 > > be a more efficient way, like working only with offsets and lengths
 > instead
 > > of copying the string again and again.
 > >
 >
 > You think worse of String.Mid() than it deserves, IMHO. Gambas strings
 > are triples of a pointer to some data, a start index and a length, and
 > the built-in string functions take care not to copy a string when it's
 > not necessary. The plain Mid$() function (dealing with ASCII strings
 only)
 > is implemented as a constant-time operation which simply takes your
 input
 > string and adjusts the start index and length to give you the
 requested
 > portion of the string. The string doesn't even have to be read, much
 less
 > copied, to do this.
 >
 > Now, the String.Mid() function is 

[Gambas-user] reparent menu item

2017-06-17 Thread Leon Davis
Using Gambas v3.9.2 and GTK+3

Is there a safe way to reparent a menu item during runtime? Any help would
be greatly appreciated.

Leon
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] [Gambas Bug Tracker] Bug #1113: ODBC driver problem: driver connects but does not exec query

2017-06-17 Thread bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1113=L21haW4-

Comment #8 by PICCORO LENZ MCKAY:

hi, zxMarce, thanks for take a shot.. i hope u can doit more due i now very 
busy.. i was thinking.. why odbc to sqlite if there's native sqlite..
well the problem its that must be a standar... odbc makes gambas able to 
connect to any DBMS source

maybe the odbc sqlite driver does not returns the right data? using mysql-odbc 
the SELECT statement returns the amount of rows.. the rest of odbc does not 
return amount of rows... so we have here a controversy.. due maybe we dont know 
where resides the problem

for now i'll make some "notes" about current state in the new odbc wiki of 
gambas (i split the odbc DSN explanation respect gambas specific info), 

and also now, depend on odbc driver module using, there's no current way to 
fill a gridview using the Data event with odbc... due mayority of odbc module 
drivers does not return any info about amount of rows when a SELECT statement 
are used like mysql-odbc does..



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] [Gambas Bug Tracker] Bug #1113: ODBC driver problem: driver connects but does not exec query

2017-06-17 Thread bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1113=L21haW4-

Comment #7 by zxMarce:

Piccoro,

Got more details. This problem would occur with any statement/query that does 
not return data.
For example a CREATE TABLE, DROP TABLE, etc. kind of query.

This occurs when the ODBC SQLExecDirect() call returns code SQL_NO_DATA 
(decimal 100).
My patch attempt only made the problem worse, because now the interpreter 
SEGFAULTs when I take SQL_NO_DATA into account as non-error value.

But the SEGFAULT occurs well after the query is actually run, same as the error 
you encountered.
Still digging...

zxMarce.



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] [Gambas Bug Tracker] Bug #1113: ODBC driver problem: driver connects but does not exec query

2017-06-17 Thread bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1113=L21haW4-

Comment #6 by zxMarce:

Piccoro,

Found out the statement IS executed, this is, in this case the table IS created 
if it did not exist.
You may want to change the bug title, which is misleading.

Anyway, for some reason not yet fully known, the component does fail with an 
internal error when it should not.
Don't know where or why yet though.

zxMarce.



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] [Gambas Bug Tracker] Bug #1113: ODBC driver problem: driver connects but does not exec query

2017-06-17 Thread bugtracker
http://gambaswiki.org/bugtracker/edit?object=BUG.1113=L21haW4-

Comment #5 by zxMarce:

Piccoro,

Just installed SQLite3 on my home laptop. After some twiddling I got the right 
connection string and the test program I once sent you connected OK.
You're correct that there's something wrong when creating tables in SQLite3, 
and it does not matter if the "IF NOT EXISTS" clause is present or not.
I'll investigate further on the matter.

zxMarce.



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Help needed from regexp gurus

2017-06-17 Thread Jussi Lahtinen
I think I would do something like:

  Dim ii As Integer
  Dim sStr As String = "abc defg hijkl"
  Dim sWords As String[]

  sWords = Split(sStr, " ")

  For ii = 0 To 2
   Print sWords[ii]
  Next




Jussi

On Sun, Jun 18, 2017 at 2:57 AM, Fernando Cabral <
fernandojosecab...@gmail.com> wrote:

> Tobi
>
> One more thing about the way I wish it could work (I remember having done
> this in C perhaps 30 years ago). The pseudo-code bellow is pretty
> schematic, but I think it will clarify the issue.
>
> Let p and l be arrays of integers and s be the string "abc defg hijkl"
>
> So, after traversing the string we would have the following result:
> p[0] = offset of "a" (0)
> l[0] = length of "abc" (3)
> p[1] = offset of "d" (4)
> l[1] = lenght of "defg" (4)
> p[2] = offset of "h" (9)
> l[2] = lenght of "hijkl" (5).
>
> After this, each word could be retrieved in the following manner:
>
> for i = 0 to 2
> print mid(s, p[i], l[i])
> next
>
> I think this would be the most efficient way to do it. But I can't find how
> to do it in Gambas using Regex.
>
> Regards
>
> - fernando
>
>
> 2017-06-17 18:06 GMT-03:00 Tobias Boege :
>
> > On Sat, 17 Jun 2017, Fernando Cabral wrote:
> > > Still beating my head against the wall due to my lack of knowledge
> about
> > > the PCRE methods and properties... Because of this, I have progressed
> not
> > > only very slowly but also -- I fell -- in a very inelegant way. So
> > perhaps
> > > you guys who are more acquainted with PCRE might be able to hint me on
> a
> > > better solution.
> > >
> > > I want to search a long string that can contain a sentence, a paragraph
> > or
> > > even a full text. I wanna find and isolate every word it contains. A
> word
> > > is defined as any sequence of alphabetic characters followed by a
> > > non-alphatetic character.
> > >
> >
> > The Mathematician in me can't resist to point this out: you hopefully
> > wanted
> > to define "word in a string" as "a *longest* sequence of alphabetic
> > characters
> > followed by a non-alphabetic character (or the end of the string)". Using
> > your
> > definition above, the words in "abc:" would be "c", "bc" and "abc",
> whereas
> > you probably only wanted "abc" (the longest of those).
> >
> > > The sample code bellow does work, but I don't feel it is as elegant and
> > as
> > > fast as it could and should be.  Especially the way I am traversing the
> > > string from the beginning to the end. It looks awkward and slow. There
> > must
> > > be a more efficient way, like working only with offsets and lengths
> > instead
> > > of copying the string again and again.
> > >
> >
> > You think worse of String.Mid() than it deserves, IMHO. Gambas strings
> > are triples of a pointer to some data, a start index and a length, and
> > the built-in string functions take care not to copy a string when it's
> > not necessary. The plain Mid$() function (dealing with ASCII strings
> only)
> > is implemented as a constant-time operation which simply takes your input
> > string and adjusts the start index and length to give you the requested
> > portion of the string. The string doesn't even have to be read, much less
> > copied, to do this.
> >
> > Now, the String.Mid() function is somewhat more complicated, because
> > UTF-8 strings have variable-width characters, which makes it difficult
> > to map byte indices to character positions. To implement String.Mid(),
> > your string has to be read, but, again, not copied.
> >
> > Extracting a part of a string is a non-destructive operation in Gambas
> > and no copying takes place. (Concatenating strings, on the other hand,
> > will copy.) So, there is some reading overhead (if you need UTF-8
> strings),
> > but it's smaller than you probably thought.
> >
> > > Dim Alphabetics as string "abc...zyzABC...ZYZ"
> > > Dim re as RegExp
> > > Dim matches as String []
> > > Dim RawText as String
> > >
> > > re.Compile("([" & Alphabetics & "]+?)([^" & Alphabetics & "]+)",
> > > RegExp.utf8)
> > > RawText = "abc12345def ghi jklm mno p1"
> > >
> > > Do While RawText
> > >  re.Exec(RawText)
> > >  matches.add(re[1].text)
> > >  RawText = String.Mid(RawText, String.Len(re.text) + 1)
> > > Loop
> > >
> > > For i = 0 To matches.Count - 1
> > >   Print matches[i]
> > > Next
> > >
> > >
> > > Above code correctly finds "abc, def, ghi, jlkm, mno, p". But the
> tricks
> > I
> > > have used are cumbersome (like advancing with string.mid() and
> resorting
> > to
> > > re[1].text and re.text.
> > >
> >
> > Well, I think you can't use PCRE alone to solve your problem, if you want
> > to capture a variable number of words in your submatches. I did a bit of
> > reading and from what I gather [1][2] capturing group numbers are
> assigned
> > based on the verbatim regular expression, i.e. the number of submatches
> > you can receive is limited by the number of "(...)" constructs in your
> > expression; and the (otherwise very nifty) recursion operator (?R) does
> > not give 

Re: [Gambas-user] Help needed from regexp gurus

2017-06-17 Thread Fernando Cabral
Tobi

One more thing about the way I wish it could work (I remember having done
this in C perhaps 30 years ago). The pseudo-code bellow is pretty
schematic, but I think it will clarify the issue.

Let p and l be arrays of integers and s be the string "abc defg hijkl"

So, after traversing the string we would have the following result:
p[0] = offset of "a" (0)
l[0] = length of "abc" (3)
p[1] = offset of "d" (4)
l[1] = lenght of "defg" (4)
p[2] = offset of "h" (9)
l[2] = lenght of "hijkl" (5).

After this, each word could be retrieved in the following manner:

for i = 0 to 2
print mid(s, p[i], l[i])
next

I think this would be the most efficient way to do it. But I can't find how
to do it in Gambas using Regex.

Regards

- fernando


2017-06-17 18:06 GMT-03:00 Tobias Boege :

> On Sat, 17 Jun 2017, Fernando Cabral wrote:
> > Still beating my head against the wall due to my lack of knowledge about
> > the PCRE methods and properties... Because of this, I have progressed not
> > only very slowly but also -- I fell -- in a very inelegant way. So
> perhaps
> > you guys who are more acquainted with PCRE might be able to hint me on a
> > better solution.
> >
> > I want to search a long string that can contain a sentence, a paragraph
> or
> > even a full text. I wanna find and isolate every word it contains. A word
> > is defined as any sequence of alphabetic characters followed by a
> > non-alphatetic character.
> >
>
> The Mathematician in me can't resist to point this out: you hopefully
> wanted
> to define "word in a string" as "a *longest* sequence of alphabetic
> characters
> followed by a non-alphabetic character (or the end of the string)". Using
> your
> definition above, the words in "abc:" would be "c", "bc" and "abc", whereas
> you probably only wanted "abc" (the longest of those).
>
> > The sample code bellow does work, but I don't feel it is as elegant and
> as
> > fast as it could and should be.  Especially the way I am traversing the
> > string from the beginning to the end. It looks awkward and slow. There
> must
> > be a more efficient way, like working only with offsets and lengths
> instead
> > of copying the string again and again.
> >
>
> You think worse of String.Mid() than it deserves, IMHO. Gambas strings
> are triples of a pointer to some data, a start index and a length, and
> the built-in string functions take care not to copy a string when it's
> not necessary. The plain Mid$() function (dealing with ASCII strings only)
> is implemented as a constant-time operation which simply takes your input
> string and adjusts the start index and length to give you the requested
> portion of the string. The string doesn't even have to be read, much less
> copied, to do this.
>
> Now, the String.Mid() function is somewhat more complicated, because
> UTF-8 strings have variable-width characters, which makes it difficult
> to map byte indices to character positions. To implement String.Mid(),
> your string has to be read, but, again, not copied.
>
> Extracting a part of a string is a non-destructive operation in Gambas
> and no copying takes place. (Concatenating strings, on the other hand,
> will copy.) So, there is some reading overhead (if you need UTF-8 strings),
> but it's smaller than you probably thought.
>
> > Dim Alphabetics as string "abc...zyzABC...ZYZ"
> > Dim re as RegExp
> > Dim matches as String []
> > Dim RawText as String
> >
> > re.Compile("([" & Alphabetics & "]+?)([^" & Alphabetics & "]+)",
> > RegExp.utf8)
> > RawText = "abc12345def ghi jklm mno p1"
> >
> > Do While RawText
> >  re.Exec(RawText)
> >  matches.add(re[1].text)
> >  RawText = String.Mid(RawText, String.Len(re.text) + 1)
> > Loop
> >
> > For i = 0 To matches.Count - 1
> >   Print matches[i]
> > Next
> >
> >
> > Above code correctly finds "abc, def, ghi, jlkm, mno, p". But the tricks
> I
> > have used are cumbersome (like advancing with string.mid() and resorting
> to
> > re[1].text and re.text.
> >
>
> Well, I think you can't use PCRE alone to solve your problem, if you want
> to capture a variable number of words in your submatches. I did a bit of
> reading and from what I gather [1][2] capturing group numbers are assigned
> based on the verbatim regular expression, i.e. the number of submatches
> you can receive is limited by the number of "(...)" constructs in your
> expression; and the (otherwise very nifty) recursion operator (?R) does
> not give you an unlimited number of capturing groups, sadly.
>
> Anyway, I think by changing your regular expression, you can let PCRE take
> care of the string advancement, like so:
>
>1 #!/usr/bin/gbs3
>2
>3 Use "gb.pcre"
>4
>5 Public Sub Main()
>6   Dim r As New RegExp
>7   Dim s As string
>8
>9   r.Compile("([[:alpha:]]+)[[:^alpha:]]+(.*$)", RegExp.UTF8)
>   10   s = "abc12345def ghi jklm mno p1"
>   11   Print "Subject:";; s
>   12   Do
>   13 r.Exec(s)
>   14 If r.Offset = -1 Then Break
>   15

Re: [Gambas-user] Help needed from regexp gurus

2017-06-17 Thread Fernando Cabral
Thank you, Tobi, for taking the time to comment on my issues. I will ponder
the following.

2017-06-17 18:06 GMT-03:00 Tobias Boege :

> On Sat, 17 Jun 2017, Fernando Cabral wrote:
> >> Still beating my head against the wall due to my lack of knowledge about
> >> the PCRE methods and properties... Because of this, I have progressed
> not
> >> only very slowly but also -- I fell -- in a very inelegant way. So
> perhaps
> >> you guys who are more acquainted with PCRE might be able to hint me on
> a
> >> better solution.
> >>
> >> I want to search a long string that can contain a sentence, a
> paragraph or
> >> even a full text. I wanna find and isolate every word it contains. A
> word
> >> is defined as any sequence of alphabetic characters followed by a
> >> non-alphatetic character.
>
> >The Mathematician in me can't resist to point this out: you hopefully
> wanted
> >to define "word in a string" as "a *longest* sequence of alphabetic
> characters
> >followed by a non-alphabetic character (or the end of the string)".
> Using your
> >definition above, the words in "abc:" would be "c", "bc" and "abc",
> whereas
> >you probably only wanted "abc" (the longest of those).
>
> Right, the longest sequence. But I can't see why my definition is not
equivalent to yours, even thou
it is simpler. "A word is defined as any sequence of alphabetic characters
followed by a non-alphabetic character" has to be the longest, no matter
what. See, in "abc", "a" and "ab" are not followed by a non-alphabetic, so
you have to keep advancing. "abc" is followed by a non-alphabetic, so it
will comply with the definition.

So I think we can do without stating it has to be the longest sequence. If
I am wrong, I still can' t see why.


> >> The sample code bellow does work, but I don't feel it is as elegant and
> as
> >> fast as it could and should be.  Especially the way I am traversing the
> >> string from the beginning to the end. It looks awkward and slow. There
> must
> >> be a more efficient way, like working only with offsets and lengths
> instead
> >> of copying the string again and again.
>
> >You think worse of String.Mid() than it deserves, IMHO. Gambas strings
> >are triples of a pointer to some data, a start index and a length, and
> >the built-in string functions take care not to copy a string when it's
> >not necessary. The plain Mid$() function (dealing with ASCII strings only)
> >is implemented as a constant-time operation which simply takes your input
> >string and adjusts the start index and length to give you the requested
> >portion of the string. The string doesn't even have to be read, much less
> >copied, to do this.
>
> >Now, the String.Mid() function is somewhat more complicated, because
> >UTF-8 strings have variable-width characters, which makes it difficult
> >to map byte indices to character positions. To implement String.Mid(),
> >your string has to be read, but, again, not copied.
>
> Right. Since I am workings with Portuguese, it has to be UTF8. So I can't
avoid using
String.Mid().

But I still understand it has to be copied because I am doing a

str = String.Mid(str, HowMany)

In this case I would guess it has to be copied because the original
contents is shrunk, which
happens again and again, until nothing is left to be scanned. I understand
Gambas does not do
garbage collection as old basic used to do, but still, I suppose it
eventually will have to recover
unused memory.




> > Extracting a part of a string is a non-destructive operation in Gambas
> > and no copying takes place. (Concatenating strings, on the other hand,
> > will copy.) So, there is some reading overhead (if you need UTF-8
> strings),
> > but it's smaller than you probably thought.
>
> As per above, in this case it is not only extracting, but overwriting the
contents itself.


> > Dim Alphabetics as string "abc...zyzABC...ZYZ"
> > Dim re as RegExp
> > Dim matches as String []
> > Dim RawText as String
> >
> > re.Compile("([" & Alphabetics & "]+?)([^" & Alphabetics & "]+)",
> > RegExp.utf8)
> > RawText = "abc12345def ghi jklm mno p1"
> >
> > Do While RawText
> >  re.Exec(RawText)
> >  matches.add(re[1].text)
> >  RawText = String.Mid(RawText, String.Len(re.text) + 1)
> > Loop
> >
> > For i = 0 To matches.Count - 1
> >   Print matches[i]
> > Next
> >
> >
> > Above code correctly finds "abc, def, ghi, jlkm, mno, p". But the tricks
> I
> > have used are cumbersome (like advancing with string.mid() and resorting
> to
> > re[1].text and re.text.
> >
>
> >Well, I think you can't use PCRE alone to solve your problem, if you want
> >to capture a variable number of words in your submatches. I did a bit of
> >reading and from what I gather [1][2] capturing group numbers are
> assigned
> >based on the verbatim regular expression, i.e. the number of submatches
> >you can receive is limited by the number of "(...)" constructs in your
> >expression; and the (otherwise very nifty) recursion operator (?R) does
> >not 

Re: [Gambas-user] Help needed from regexp gurus

2017-06-17 Thread Tobias Boege
On Sat, 17 Jun 2017, Fernando Cabral wrote:
> Still beating my head against the wall due to my lack of knowledge about
> the PCRE methods and properties... Because of this, I have progressed not
> only very slowly but also -- I fell -- in a very inelegant way. So perhaps
> you guys who are more acquainted with PCRE might be able to hint me on a
> better solution.
> 
> I want to search a long string that can contain a sentence, a paragraph or
> even a full text. I wanna find and isolate every word it contains. A word
> is defined as any sequence of alphabetic characters followed by a
> non-alphatetic character.
> 

The Mathematician in me can't resist to point this out: you hopefully wanted
to define "word in a string" as "a *longest* sequence of alphabetic characters
followed by a non-alphabetic character (or the end of the string)". Using your
definition above, the words in "abc:" would be "c", "bc" and "abc", whereas
you probably only wanted "abc" (the longest of those).

> The sample code bellow does work, but I don't feel it is as elegant and as
> fast as it could and should be.  Especially the way I am traversing the
> string from the beginning to the end. It looks awkward and slow. There must
> be a more efficient way, like working only with offsets and lengths instead
> of copying the string again and again.
> 

You think worse of String.Mid() than it deserves, IMHO. Gambas strings
are triples of a pointer to some data, a start index and a length, and
the built-in string functions take care not to copy a string when it's
not necessary. The plain Mid$() function (dealing with ASCII strings only)
is implemented as a constant-time operation which simply takes your input
string and adjusts the start index and length to give you the requested
portion of the string. The string doesn't even have to be read, much less
copied, to do this.

Now, the String.Mid() function is somewhat more complicated, because
UTF-8 strings have variable-width characters, which makes it difficult
to map byte indices to character positions. To implement String.Mid(),
your string has to be read, but, again, not copied.

Extracting a part of a string is a non-destructive operation in Gambas
and no copying takes place. (Concatenating strings, on the other hand,
will copy.) So, there is some reading overhead (if you need UTF-8 strings),
but it's smaller than you probably thought.

> Dim Alphabetics as string "abc...zyzABC...ZYZ"
> Dim re as RegExp
> Dim matches as String []
> Dim RawText as String
> 
> re.Compile("([" & Alphabetics & "]+?)([^" & Alphabetics & "]+)",
> RegExp.utf8)
> RawText = "abc12345def ghi jklm mno p1"
> 
> Do While RawText
>  re.Exec(RawText)
>  matches.add(re[1].text)
>  RawText = String.Mid(RawText, String.Len(re.text) + 1)
> Loop
> 
> For i = 0 To matches.Count - 1
>   Print matches[i]
> Next
> 
> 
> Above code correctly finds "abc, def, ghi, jlkm, mno, p". But the tricks I
> have used are cumbersome (like advancing with string.mid() and resorting to
> re[1].text and re.text.
> 

Well, I think you can't use PCRE alone to solve your problem, if you want
to capture a variable number of words in your submatches. I did a bit of
reading and from what I gather [1][2] capturing group numbers are assigned
based on the verbatim regular expression, i.e. the number of submatches
you can receive is limited by the number of "(...)" constructs in your
expression; and the (otherwise very nifty) recursion operator (?R) does
not give you an unlimited number of capturing groups, sadly.

Anyway, I think by changing your regular expression, you can let PCRE take
care of the string advancement, like so:

   1 #!/usr/bin/gbs3
   2
   3 Use "gb.pcre"
   4
   5 Public Sub Main()
   6   Dim r As New RegExp
   7   Dim s As string
   8
   9   r.Compile("([[:alpha:]]+)[[:^alpha:]]+(.*$)", RegExp.UTF8)
  10   s = "abc12345def ghi jklm mno p1"
  11   Print "Subject:";; s
  12   Do
  13 r.Exec(s)
  14 If r.Offset = -1 Then Break
  15 Print " ->";; r[1].Text
  16 s = r[2].Text
  17   Loop While s
  18 End

Output:

  Subject: abc12345def ghi jklm mno p1
   -> abc
   -> def
   -> ghi
   -> jklm
   -> mno
   -> p

But, I think, this is less efficient than using String.Mid(). The trailing
group (.*$) _may_ make the PCRE library read the entire subject every time.
And I believe gb.pcre will copy your submatch string when returning it.
If you care deeply about this, you'll have to trace the code in gb.pcre
and main/gbx (the interpreter) to see what copies strings and what doesn't.

Regards,
Tobi

[1] http://www.regular-expressions.info/recursecapture.html (Capturing Groups 
Inside Recursion or Subroutine Calls)
[2] http://www.rexegg.com/regex-recursion.html (Groups Contents and Numbering 
in Recursive Expressions)

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

--
Check out the vibrant tech community on one of the 

Re: [Gambas-user] DesktopWindow.Name; Unexpected result

2017-06-17 Thread Gianluigi
Hi Tobias,

I have Ubuntu with Unity but I trust in yours words :-)

Regards
Gianluigi

2017-06-17 14:50 GMT+02:00 Tobias Boege :

> On Sat, 17 Jun 2017, Gianluigi wrote:
> > 2017-06-17 13:51 GMT+02:00 adamn...@gmail.com :
> >
> > >
> > > Ah! Now I see where your confusion lies...
> > > 1) DesktopWindow.Name : "i.e. its title as specified by the application
> > > that owns this window."
> > > 2) DesktopWindow.VisibleName : " i.e. the window title as displayed by
> the
> > > window manager."
> > >
> > > The difference is subtle and not easy to find an example for, but it
> does
> > > happen I can assure you.
> > >
> >
> > OK, I'll take your word for it.
> >
>
> I can get something like this here easily by opening two konqueror windows
> and pointing them to the same directory (see screenshot). However, the
> properties of the DesktopWindow objects look like this:
>
>   $ ./konqueror-windows.gbs3
>   Name: var - Konqueror   VisibleName: var - Konqueror
>   Name: var - Konqueror   VisibleName:
>
> So, apparently this can happen, too.
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] Help needed from regexp gurus

2017-06-17 Thread Fernando Cabral
Still beating my head against the wall due to my lack of knowledge about
the PCRE methods and properties... Because of this, I have progressed not
only very slowly but also -- I fell -- in a very inelegant way. So perhaps
you guys who are more acquainted with PCRE might be able to hint me on a
better solution.

I want to search a long string that can contain a sentence, a paragraph or
even a full text. I wanna find and isolate every word it contains. A word
is defined as any sequence of alphabetic characters followed by a
non-alphatetic character.

The sample code bellow does work, but I don't feel it is as elegant and as
fast as it could and should be.  Especially the way I am traversing the
string from the beginning to the end. It looks awkward and slow. There must
be a more efficient way, like working only with offsets and lengths instead
of copying the string again and again.

Dim Alphabetics as string "abc...zyzABC...ZYZ"
Dim re as RegExp
Dim matches as String []
Dim RawText as String

re.Compile("([" & Alphabetics & "]+?)([^" & Alphabetics & "]+)",
RegExp.utf8)
RawText = "abc12345def ghi jklm mno p1"

Do While RawText
 re.Exec(RawText)
 matches.add(re[1].text)
 RawText = String.Mid(RawText, String.Len(re.text) + 1)
Loop

For i = 0 To matches.Count - 1
  Print matches[i]
Next


Above code correctly finds "abc, def, ghi, jlkm, mno, p". But the tricks I
have used are cumbersome (like advancing with string.mid() and resorting to
re[1].text and re.text.

-- 
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: fernandojosecab...@gmail.com
Facebook: f...@fcabral.com.br
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] DesktopWindow.Name; Unexpected result

2017-06-17 Thread Tobias Boege
On Sat, 17 Jun 2017, Gianluigi wrote:
> 2017-06-17 13:51 GMT+02:00 adamn...@gmail.com :
> 
> >
> > Ah! Now I see where your confusion lies...
> > 1) DesktopWindow.Name : "i.e. its title as specified by the application
> > that owns this window."
> > 2) DesktopWindow.VisibleName : " i.e. the window title as displayed by the
> > window manager."
> >
> > The difference is subtle and not easy to find an example for, but it does
> > happen I can assure you.
> >
> 
> OK, I'll take your word for it.
> 

I can get something like this here easily by opening two konqueror windows
and pointing them to the same directory (see screenshot). However, the
properties of the DesktopWindow objects look like this:

  $ ./konqueror-windows.gbs3
  Name: var - Konqueror   VisibleName: var - Konqueror
  Name: var - Konqueror   VisibleName:

So, apparently this can happen, too.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
#!/usr/bin/gbs3

Use "gb.desktop"

Public Sub Main()
  Dim w As DesktopWindow

  For Each w In Desktop.Windows
If w.Name Not Like "*konqueror*" Then Continue
Print "Name:";; w.Name, "VisibleName:";; w.VisibleName
  Next
End
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] DesktopWindow.Name; Unexpected result

2017-06-17 Thread Gianluigi
2017-06-17 13:51 GMT+02:00 adamn...@gmail.com :

>
> Ah! Now I see where your confusion lies...
> 1) DesktopWindow.Name : "i.e. its title as specified by the application
> that owns this window."
> 2) DesktopWindow.VisibleName : " i.e. the window title as displayed by the
> window manager."
>
> The difference is subtle and not easy to find an example for, but it does
> happen I can assure you.
>

OK, I'll take your word for it.

You understand how an application sets the Title of a window that it
> displays, OK? Hence you see the file name in the title for the windows in
> your output. This is the .Name property value.
> Now there are situations where the window manager itself will modify the
> title for some reason or other.  I cannot think up an example but maybe you
> have seen somewhere a window title that looked something like "My Window -
> some info" and if you had two of these open the titles would be something
> like "My Window - some info:1" and "My Window - some info:2". These titles
> are set by the Window Manager, from the title supplied by the owning
> application and for its' own sweet reasons. In other words, it is not easy
> to "make this happen" as it depends on the window manager in use and its
> logic for re-titling specific windows.
>
> Now here is the reason for having the two properties.  If you are
> searching for a specific window by it's expected title, i.e. the
> application set Title, then exact match searches will fail when the window
> manager has altered it. So then we use DesktopWindow.Name ... and get a
> list if there are more than one.  But if we want to act on a specific,
> re-titled, window then Desktop.Window.VisibleName can be used.
>
> I have said this before, and no doubt will say it again.
> Above my desk is a sign that says : "Read EVERY word in the Gambas help
> page".  I put it up there nearly 10 years ago when I was learning Gambas
> for the first time and even today I occasionally have to refer to it when I
> get frustrated by something that I don't understand about Gambas.  I
> recommend you get a similar sign.  :-)
>

That's good advice, I'll keep that in mind. 
Thank you very much for the exhaustive explanations.

Regards
Gianluigi
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] DesktopWindow.Name; Unexpected result

2017-06-17 Thread adamn...@gmail.com
On Sat, 17 Jun 2017 12:19:53 +0200
Gianluigi  wrote:

> Sorry but I do not understand the difference;
> From Gambas documentation on DesktopWindow.VisibleName (gb.desktop):
> Returns the window visible name, i.e. the window title as displayed by the
> window manager.
> The visible name may be different from the name, when two or more windows
> have the same name.
> 

Ah! Now I see where your confusion lies...
1) DesktopWindow.Name : "i.e. its title as specified by the application that 
owns this window."
2) DesktopWindow.VisibleName : " i.e. the window title as displayed by the 
window manager."

The difference is subtle and not easy to find an example for, but it does 
happen I can assure you.

You understand how an application sets the Title of a window that it displays, 
OK? Hence you see the file name in the title for the windows in your output. 
This is the .Name property value.
Now there are situations where the window manager itself will modify the title 
for some reason or other.  I cannot think up an example but maybe you have seen 
somewhere a window title that looked something like "My Window - some info" and 
if you had two of these open the titles would be something like "My Window - 
some info:1" and "My Window - some info:2". These titles are set by the Window 
Manager, from the title supplied by the owning application and for its' own 
sweet reasons. In other words, it is not easy to "make this happen" as it 
depends on the window manager in use and its logic for re-titling specific 
windows.

Now here is the reason for having the two properties.  If you are searching for 
a specific window by it's expected title, i.e. the application set Title, then 
exact match searches will fail when the window manager has altered it. So then 
we use DesktopWindow.Name ... and get a list if there are more than one.  But 
if we want to act on a specific, re-titled, window then 
Desktop.Window.VisibleName can be used.

I have said this before, and no doubt will say it again.
Above my desk is a sign that says : "Read EVERY word in the Gambas help page".  
I put it up there nearly 10 years ago when I was learning Gambas for the first 
time and even today I occasionally have to refer to it when I get frustrated by 
something that I don't understand about Gambas.  I recommend you get a similar 
sign.  :-)

regards
b






-- 
B Bruen 

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] sqlite3 component can't seem to handle very large numbers

2017-06-17 Thread Herman Borsje

Thanks Benoît and Tobias!

Problem solved by changing the data-type of the fields in Sqlite from 
INTEGER to BIGINT like so:


- select * from {table} into {temptable}
- create {newtable} (with BIGINT fields)
- insert into {newtable} select * from {temptable}
- drop {temptable}

Regards,
Herman

Op 17-06-17 om 01:49 schreef Benoît Minisini via Gambas-user:

Le 17/06/2017 à 01:31, Tobias Boege a écrit :

On Sat, 17 Jun 2017, Herman Borsje wrote:

When I retrieve a result from a sqlite3 database which holds very large
numbers in some fields, I get weird results. Up to 10 digits works 
okay, but

larger numbers are incorrect. Any ideas as to what's going wrong?

I am using Gambas 3.9.2 on Linux Mint 18.1

Tabledef: id INTEGER, name TEXT;

Database records:

id name

1234567890test1

12345678901  test2

123456789010test3


Public Sub Button1_Click()

   Dim rs As Result
   Dim con As New Connection
   con.Name = "test.db"
   con.Type = "sqlite3"
   con.Open

   rs = con.Exec("select * from test")

   For Each rs
 Debug Cstr(rs!id) & ": " & rs!name
   Next

   con.Close

End

Debug results:

FMain.Button1_Click.14: 1234567890: test1
FMain.Button1_Click.14: 0: test2
FMain.Button1_Click.14: 6714656: test3



The SQLite documentation tells me that SQLite3's INTEGER datatype can
consist of 1, 2, 3, 4, 6 or 8 bytes, depending on the magnitude of the
value to be stored, whereas Gambas' normal Integer type is always four
bytes, or 32 bits.

What you call "larger numbers" are most likely just numbers that cross
the boundaries of 32 bits. At least the two numbers you listed above,
where the retrieval appears to fail, have 34 and 37 bits respectively.

In the attached script, I tried CLong() (Long is always 8 bytes in
Gambas), but to no avail. It seems that the faulty conversion is already
done in the database driver and has to be fixed there. From glancing
at the source code, the mapping between SQLite and Gambas datatypes is:

   Gambas ->  SQLite3 SQLite3-> Gambas
   + --+--
  Integer  |INT4 INTEGER, | \
Long   |   BIGINTINT, INT4, INT2, |  |
 SMALLINT,|  |- Integer
 MEDIUMINT| /
   BIGINT, INT8   | Long

I would suggest to map INTEGER to Long instead of Integer, but Benoit,
being the driver author, has to confirm.

Regards,
Tobi



SQLite fields internally do not have datatypes. You can store any 
value in any field.


So I chose INTEGER to represent 4 bytes integer, and BIGINT to 
represent 8 bytes integer, like in MySQL.


It's just a convention, but a convention was needed.

Regards,




--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user