I am having problems with ReadFile():
1) I need it to be synchronous: it opens a file for reading, I process it, and the main process does not continue until the operation is done. Instead, I get to use a callback...
2) the manual says « OpenFileRequester()() needs to be called before to have access to local files.» But I open the file as a data repository! How can I need to open a requester before!?
ReadFile oddities - synchronous, open specific local file
Re: ReadFile oddities - synchronous, open specific local fil
Not even `IncludeBinary` is there...
If the limitation is because of the JS concept of running in a browser from random web pages hence need for security, instead of being code run from a trusted application, well, then JS is not enough. It must be "patched" and augmented with the needed bits of "local OS".
Already the access to SQLite files is not there... How can one load data into the application?
If the limitation is because of the JS concept of running in a browser from random web pages hence need for security, instead of being code run from a trusted application, well, then JS is not enough. It must be "patched" and augmented with the needed bits of "local OS".
Already the access to SQLite files is not there... How can one load data into the application?
Re: ReadFile oddities - synchronous, open specific local fil
With Php :mdp wrote:How can one load data into the application?
https://www.spiderbasic.com/documentati ... quest.html
➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
➽ http://falsam.com
Sorry for my poor english
Re: ReadFile oddities - synchronous, open specific local fil
perhaps SpiderBite fulfils your requirements:mdp wrote:Already the access to SQLite files is not there... How can one load data into the application?
Code: Select all
; either include "SpiderBite.sbi":
; XIncludeFile "[YourPathTo]/SpiderBite.sbi"
;
; ... or copy "SpiderBite.res" to SpiderBasics Residents-Folder
#SpiderBite_Profile = "default"
Procedure GetDataCallback(Success, Result.s)
Debug "Success: " + Success
Debug "Result: " + Result
EndProcedure
EnablePbCgi
UseSQLiteDatabase()
ProcedureDLL.s GetData()
Protected ReturnValue.s
Protected DB
DB = OpenDatabase(#PB_Any, ":memory:", "", "", #PB_Database_SQLite)
If DB
DatabaseUpdate(DB, "Create Table SuperHeroes (Prename TEXT, Surname TEXT)")
DatabaseUpdate(DB, "Insert Into SuperHeroes (Prename, Surname) Values ('Peter', 'Parker')")
DatabaseUpdate(DB, "Insert Into SuperHeroes (Prename, Surname) Values ('Bruce', 'Wayne')")
DatabaseUpdate(DB, "Insert Into SuperHeroes (Prename, Surname) Values ('Clark', 'Kent')")
If DatabaseQuery(DB, "Select * From SuperHeroes Where Prename = 'Peter'")
While NextDatabaseRow(DB)
ReturnValue + GetDatabaseString(DB, 1) + "," + GetDatabaseString(DB, 0) + #CRLF$
Wend
FinishDatabaseQuery(DB)
EndIf
CloseDatabase(DB)
EndIf
ProcedureReturn ReturnValue
EndProcedure
DisablePbCgi
GetData()
If 1=2 ; prevent removing the 'unneeded' callback
GetDataCallback(0, "")
EndIf
(the documentation is in german, but you can use DeepL for the translation)
Greetings ... Peter
Re: ReadFile oddities - synchronous, open specific local fil
Sorry, I don't get it... Do you mean using a network server? It is totally overkill. This approach would restrict SB to client-server applications. To use SB for local application development, possibly offline, we need to access data. This mean custom binary/text (e.g. CSV, "blit" etc.), DB (SQLite) etc.falsam wrote:With Php :mdp wrote:How can one load data into the application?
https://www.spiderbasic.com/documentati ... quest.html
EDIT: unless SB packs a minimal, maybe transparent server... It's not impossible to implement, and it can be done with minimal libraries! It's a hack, but we need a hack to make full applications out of web-based code.
Re: ReadFile oddities - synchronous, open specific local fil
At the moment, I thought that the best solution seems to embed a JSON literal with IncludeFile.
Am I missing anything? Are there better ideas?
I would love to access the blit of an array of structures, but never tried even in PB...
I would also like to free the memory of source literal objects - just to do things properly.
Am I missing anything? Are there better ideas?
I would love to access the blit of an array of structures, but never tried even in PB...
I would also like to free the memory of source literal objects - just to do things properly.
Re: ReadFile oddities - synchronous, open specific local fil
perhaps your Json-File with LoadJson()?mdp wrote:Are there better ideas?
btw.: what is a 'blit'?
Greetings ... Peter
Re: ReadFile oddities - synchronous, open specific local fil
Peter wrote:perhaps your Json-File with LoadJson()?
You mean we cannot access random local files but we can if they are JSON formatted (which does not even have a magic header?). I am stunned, it would make no sense
It's when you dump a piece of memory (low level) that you can then load to use it with high level functions. E.g. if you have an array of 10 of a structure of a byte and an int, you could use a dump of 50 bytes as both storage and of source to load into memory. But put in there pointers (e.g. null-terminated strings), and the matter gets messy...Peter wrote:btw.: what is a 'blit'?
So basically I meant: something that you upload into memory and use directly
Re: ReadFile oddities - synchronous, open specific local fil
And in fact, I may be wrong, but the manual seems to indicate using a procedure which is part of the Requester library:mdp wrote:You mean we cannot access random local files but we can if they are JSON formatted (which does not even have a magic header?). I am stunned, it would make no sense
Filename$ The name of the file containing the JSON data. It can be an URL or a local file identifier got with SelectedFileID().
Re: ReadFile oddities - synchronous, open specific local fil
you can use LoadJSON() without Requester:
Greetings ... Peter
Code: Select all
Procedure Loaded(Type, Filename$, ObjectId)
Debug Type
Debug Filename$
Debug ObjectId
EndProcedure
Procedure LoadingError(Type, Filename$, ObjectId)
Debug Filename$ + ": loading error"
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadJSON(0, "./resources/test.json")