Found an issue in SpiderBasic ? Please report it here !
DanLJr
 
Posts: 43
Joined: Wed Jul 04, 2018 4:24 am

ArraySize() doesn't properly reflect the Array's size (BUG?)

by DanLJr Wed Jul 18, 2018 11:51 pm

ArraySize() doesn't properly reflect the size of the Array after populating an Array from a function:

Code: Select all
Dim UserInputParsedArray$(0)

CreateRegularExpression(0, "\w+")
NumberOfElements = ExtractRegularExpression(0, "qwerty asdf zxcv poiuytr", UserInputParsedArray$()) ;NumberOfElements returns 4 (four matches found)
Debug NumberOfElements ;shows 4
Debug  ArraySize(UserInputParsedArray$()) ;show 0 !!!???
;yet...

For i = 0 To 3
  Debug UserInputParsedArray$(i)
Next
;shows all elements, so ArraySize(UserInputParsedArray$()) should definitely return 4, otherwise ArraySize() is useless without running the RegEx twice with a ReDim in the middle - huh??? HOW??? Is this a bug?


Is this a bug? If not, it's never weird and undesireable behanvior.

Thoughts?
DanLJr
 
Posts: 43
Joined: Wed Jul 04, 2018 4:24 am

Re: ArraySize() doesn't properly reflect the Array's size (B

by DanLJr Sat Jul 21, 2018 1:37 am

*BUMP*???

Thinking about this, I could force a ReDim manually AFTER the {NumberOfElements = ExtractRegularExpression(0,...} so that ArraySize() would reflect the actual size, but really what is the point of ReDim and ArraySize() if it's just a "manual" process to maintain it anyhow?

Also, if I do go ahead and ReDim throughout the loop just to maintain consistency with ArraySize() (in a real-world application this loop would not be fixed to four values, rather a dynamic number of values) does it just waste additional resources? Should I just ignore ReDim and ArraySize() altogether, since they seem to do nothing and appear to have no ill effects when ignored? (Other than the ability to know the array's size without manually looping after-the-fact.)

Last related question...since the array in the example below is an argument being passed by reference to the ExtractRegularExpression function (part of the PureBasic libraries; not a user-defined function) shouldn't that function be the one to ReDim the array internally? (Is this a bad/missed implementation of the regular expression functions that manipulate arrays?)

Fred, anybody?

BTW, SpiderBasic is proving to be an AWESOME product! I'm been coding my first relatively serious project (first in SB; I've been around for a while...) in the demo version, and I'm about to purchase. Next will be to start working on some server-side stuff in PB and see if I can master the SB-PB development relationship via HTTP/JSON, etc.

Overall I"m VERY impressed and happy with SB! (Now, if we can just workout some of these array bugs / undesirable behavious...LOL)

DanLJr wrote:ArraySize() doesn't properly reflect the size of the Array after populating an Array from a function:

Code: Select all
Dim UserInputParsedArray$(0)

CreateRegularExpression(0, "\w+")
NumberOfElements = ExtractRegularExpression(0, "qwerty asdf zxcv poiuytr", UserInputParsedArray$()) ;NumberOfElements returns 4 (four matches found)
Debug NumberOfElements ;shows 4
Debug  ArraySize(UserInputParsedArray$()) ;show 0 !!!???
;yet...

For i = 0 To 3
  Debug UserInputParsedArray$(i)
Next
;shows all elements, so ArraySize(UserInputParsedArray$()) should definitely return 4, otherwise ArraySize() is useless without running the RegEx twice with a ReDim in the middle - huh??? HOW??? Is this a bug?


Is this a bug? If not, it's never weird and undesireable behanvior.

Thoughts?
User avatar
Peter
 
Posts: 553
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: ArraySize() doesn't properly reflect the Array's size (B

by Peter Sat Jul 21, 2018 3:28 pm

<OT>

DanLJr wrote:Next will be to start working on some server-side stuff in PB and see if I can master the SB-PB development relationship via HTTP/JSON, etc.

maybe that's worth a look: SpiderBite

</OT>

Greetings ... Peter
DanLJr
 
Posts: 43
Joined: Wed Jul 04, 2018 4:24 am

Re: ArraySize() doesn't properly reflect the Array's size (B

by DanLJr Mon Jul 23, 2018 12:57 am

Peter wrote:<OT>

DanLJr wrote:Next will be to start working on some server-side stuff in PB and see if I can master the SB-PB development relationship via HTTP/JSON, etc.

maybe that's worth a look: SpiderBite

</OT>

Greetings ... Peter


Ok, so I did a quick read on SpiderBite. The big question is, does this ACTUALLY work? Like well? Production-level?

If it does what it says, this would make developing the server-side of my apps (and the client-side communication as well) as simple as making a begin and end do each desired section of server-side code. A few smart decisions, and, "voilà!" you have a full-featured, client/server web/app with SpiderBasic-as-primary/only dev tool needed. (I mean, you need a PureBasic license along with SpiderBasic, but you would anyway.)

This is a BEAUTIFUL thing, Peter!

I'm going to give it a shot as soon as I get closer to deployment. It will be quite easy to mark the server-sde areas later, since I don't need to develop using any database access at this time. (Though, I WILL need to build some components with server-side DB access at some point in the future.) I'll let you know how things go with SpiderBite as soon as I get to the point where I'm ready to give it a shot! (And inline PHP could offer an easy solution to integrate things like WP - SB/PB WP plugin dev??? - by dropping-in their "rules layer" without separating the programming task beyond MAYBE having to copy a part to the right place on the server manually and changing a path or two in PHP code after-the-fact???. Interesting...)

Anything special - "gotchas"/limitations - I should know about here? (Besides the "no hardware access on the server" kinda obvious stuff?)

Exciting stuff, Peter!
DanLJr
 
Posts: 43
Joined: Wed Jul 04, 2018 4:24 am

Re: ArraySize() doesn't properly reflect the Array's size (B

by DanLJr Tue Nov 13, 2018 4:51 am

Hey Peter, I'm finally coding away with DB/PB/SpiderBite. (I tried PMing you about this issue, but my messages got stuck in Outbox. ) Hopefully you see this post here - sorry if this ends up as a cross/duplicate-post with PM or another thread. I looked around, but couldn't find a better place to post/discuss. I appreciate any insights/help you can offer on this, and I would like to thank you in advance for anything you can do to get me on the right track ASAP:

Here is the text from the PM (copied/pasted directly)...

Peter,

You've been a big help in the past, and I thought I'd just write you directly about this one, as I couldn't find a good existing topic on the forums, or perhaps I just missed it. (If I learn something valuable here, once resolved, I will share the results with the forum.)

Anyhow, here is my question...

I am having an issue using the server-side PB database code in my SB/PB/Spiderbite web-client/PBcgi-server app. It simply won't compile/run. It reports the error: 'UsePostgreSQLDatabase() is not a function, array, list, map, or macro.' How do I make this work?

The code is below. Locally, my DB info was right, so it should work, but it's not even getting that far. I'm pretty sure that Spiderbite is setup correctly, as it does recognize EnablePbCgi and such, but maybe something else is messed-up? (SpiderBite.res is in the correct location, so not that.) Again, EnablePbCgi was NOT working before adding the SpiderBite.res file to the Residents folder/ Adding it DID seem to make EnablePbCgi work, but UsePostgreSQLDatabase() is still not be recognized as valid, and of course it's a valid PB function, and necessary for my server-side DB stuff.

What I'm doing below is incredibly basic right now... just trying to verify that I can connect to the DB!

What am I doing wrong here?

Code: Select all
#SpiderBite_Profile = "default"

#SAMainWindowID = 0
#SAPostgreSQLConnection = 0

Declare Hello()
Declare.s GetAssessmentName()
Declare GetAssessmentNameCallback(Success, Result.s)

Procedure Hello()
 
  OpenWindow(#SAMainWindowID, 0, 0, 0, 0, "Testing and Assessment Center", #PB_Window_Background)
 
EndProcedure

EnablePbCgi
 
  Procedure.s GetAssessmentName()
 
    UsePostgreSQLDatabase()

    If OpenDatabase(0, "hostaddr=127.0.0.1 port=5432 dbname=skytests_assessments_db", "skytests_assessments_dbusr", "testingPW!0987")
      Debug "Connected to PostgreSQL"
    Else
      Debug "Connection failed: " + DatabaseError()
    EndIf
   
    ProcedureReturn "Hello from GetAssessmentName"
   
  EndProcedure
 
DisablePbCgi
 
Procedure GetAssessmentNameCallback(Success, Result.s)
 
  Debug ""
  Debug "GetAssessmentNameCallback"
  Debug "Success: " + Success
  Debug "Result: " + Result
   
EndProcedure

If 1=2
  GetAssessmentNameCallback(0, "")
EndIf


Thanks in advance for your help, Peter!
User avatar
Peter
 
Posts: 553
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: ArraySize() doesn't properly reflect the Array's size (B

by Peter Tue Nov 13, 2018 7:11 am

DanLJr wrote:It reports the error: 'UsePostgreSQLDatabase() is not a function, array, list, map, or macro.'


Have you set up SpiderBite as tools?

Image

see also:

https://github.com/spiderbytes/SpiderBite#spiderbite-als-spiderbasic-tools-einrichten

Greetings ... Peter
DanLJr
 
Posts: 43
Joined: Wed Jul 04, 2018 4:24 am

Re: ArraySize() doesn't properly reflect the Array's size (B

by DanLJr Tue Nov 13, 2018 2:38 pm

My tools are configured the same as yours. No luck. I am stuck and running out of time. Please help!

Image
DanLJr
 
Posts: 43
Joined: Wed Jul 04, 2018 4:24 am

Re: ArraySize() doesn't properly reflect the Array's size (B

by DanLJr Tue Nov 13, 2018 3:06 pm

Hey Peter! Ok, so I figured out part of it after posting again... Apparently, my virus protection software quarantined my spiderbite.exe file, so it was no longer in the folder and no longer accessible. I removed it from the virus vault, deleted it, recompiled to the proper location, and it does seem to be compiling my code now. Yay! (But if I try to call any of the CGI-based procedures now, I get a compile error. See below...)

Now that I have a valid spiderbite.exe in-play, while I can now compile code with PB syntax in the cgi procedures, I get a new compile error calling any of those procs, even trying to run the sample files:

'myPbCgiProcedure1() is not a function, array, list, map, or macro.'

Code: Select all
; either include "SpiderBite.sbi":
; XIncludeFile "[YourPathTo]/SpiderBite.sbi"
;
; ... or copy "SpiderBite.res" to SpiderBasics Residents-Folder

#SpiderBite_Profile = "default"

Procedure myPbCgiProcedure3Callback(Success, Result.s)
 
  Debug ""
  Debug "myPbCgiProcedure3Callback"
  Debug "Success: " + Success
  Debug "Result: " + Result
 
EndProcedure

Procedure myPbCgiProcedure4Callback(Success, Result.s)
 
  Debug ""
  Debug "myPbCgiProcedure4Callback"
  Debug "Success: " + Success
  Debug "Result: " + Result
 
EndProcedure

EnablePbCgi
 
  Procedure.s myPbCgiProcedure1()
    ProcedureReturn "Hello from myPbCgiProcedure1"
  EndProcedure
 
  Procedure.s myPbCgiProcedure2(Message.s)
    ProcedureReturn "Hello from " + Message
  EndProcedure
 
  Procedure.s myPbCgiProcedure3()
    ProcedureReturn "Hello from myPbCgiProcedure3"
  EndProcedure
 
  Procedure.s myPbCgiProcedure4(Message.s)
    ProcedureReturn "Hello from " + Message
  EndProcedure
 
DisablePbCgi

Debug myPbCgiProcedure1()                    ; without callback, without parameter
Debug myPbCgiProcedure2("myPbCgiProcedure2") ; without callback, with parameter

Debug myPbCgiProcedure3()                    ; with callback, without parameter
Debug myPbCgiProcedure4("myPbCgiProcedure4") ; with callback, with parameter

If 1=2
  myPbCgiProcedure3Callback(0, "")
  myPbCgiProcedure4Callback(0, "")
EndIf


Here's what's weird.. If I delete SpiderBite.exe, this code from the sample file will compile and run just fine. But, if spiderbite.exe exists in the folder it's configured to use in tools, then I get the above error.

Please, please help! I get over one hump and a new one appears...I've GOT to get past this configuration phase and on to the app dev phase of this project or I'm going to be late before I start...please help me to get this environment running properly. (I'm just starting to panic and get frustrated, because so much time has passed and I still don't have the environment running properly.)

Thank you and I appreciate all that you do for me and this community, Peter!

-Dan
DanLJr
 
Posts: 43
Joined: Wed Jul 04, 2018 4:24 am

Re: ArraySize() doesn't properly reflect the Array's size (B

by DanLJr Tue Nov 13, 2018 3:12 pm

Peter,

Here's the code I'm trying to run just to see the db connection code run. Success or fail, I should see some debug output, but if I call the GetAssessmentName() cgi proc - as shown in the code - it throws an error same as described - not a valid procedure...

If you remove the Debug GetAssessmentName() last line, all of the code compiles, but of course nothing happens because nothing is being called. Please help! I seem to be calling this properly, but like I said in my last message, even the sample file (code posts in last message) won't compile (same 'not a valid proc...' type message.)

I have no clue where to go from here. I patiently - and frantically! - await your reply so I can continue with my project.

Code: Select all
;Main SpiderBasic/PureBasic/SpiderBite souce code file for Skyward Assessments (SkyTests) app
;Important: 'SpiderBite.res' must be located in SpiderBasic's Residents folder

#SpiderBite_Profile = "default"

#SAMainWindowID = 0
#SAPostgreSQLConnection = 0

Procedure Hello()
 
  OpenWindow(#SAMainWindowID, 0, 0, 0, 0, "Testing and Assessment Center", #PB_Window_Background)
 
EndProcedure

EnablePbCgi
 
  Procedure.s GetAssessmentName()
 
    UsePostgreSQLDatabase()

    If OpenDatabase(0, "hostaddr=127.0.0.1 port=5432 dbname=skytests_assessments_db", "skytests_assessments_dbusr", "testingPW!0987")
      Debug "Connected to PostgreSQL"
    Else
      Debug "Connection failed: " + DatabaseError()
    EndIf
   
    ProcedureReturn "Hello from GetAssessmentName"
   
  EndProcedure
 
DisablePbCgi
 
Procedure GetAssessmentNameCallback(Success, Result.s)
 
  Debug ""
  Debug "GetAssessmentNameCallback"
  Debug "Success: " + Success
  Debug "Result: " + Result
   
EndProcedure

If 1=2
  GetAssessmentNameCallback(0, "")
EndIf

Debug GetAssessmentName()
DanLJr
 
Posts: 43
Joined: Wed Jul 04, 2018 4:24 am

Re: ArraySize() doesn't properly reflect the Array's size (B

by DanLJr Tue Nov 13, 2018 3:43 pm

Ok, so I'm answering some of my own questions here...

Apparently, it was a scope issue:

I changed Procedure.s GetAssessmentName() to ProcedureDLL.s GetAssessmentName() and the code ran. (Which means the Example files are WRONG, as they don't use ProcedureDLL, and therefore won't compile/run.)

Code: Select all
EnablePbCgi
 
  ProcedureDLL.s GetAssessmentName()
 
    UsePostgreSQLDatabase()

    If OpenDatabase(0, "host=localhost port=5432 dbname=skytests_assessments_db", "skytests_assessments_dbusr", "testingPW!0987")
      Debug "Connected to PostgreSQL"
    Else
      Debug "Connection failed: " + DatabaseError()
    EndIf
   
    ProcedureReturn "Hello from GetAssessmentName"
   
  EndProcedure
 
DisablePbCgi
Return to Bugs Reports

Who is online

Users browsing this forum: No registered users and 1 guest