QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: MLambert on February 07, 2019, 07:44:13 am

Title: Need Help to Understand Code
Post by: MLambert on February 07, 2019, 07:44:13 am
Hi,

I am trying to use the sql code to build and access sql tables. My knowledge of QB64 code is limited to a point so I need some help to understand the code.

- why doesn't debug work ??
DIM SHARED DB_Debug_Mode AS LONG: DB_Debug_Mode = 1
IF DB_Debug_Mode THEN PRINT "Columns:"; columns
- shouldn't the line say IF DB_DEBUG_MODE =1 THEN PRINT .....

- What does the ".object" do ?? I don't understand this line
IF Database(DB_Selected).Object = 0

- A ":" signifies end of command (more than one command on a line) .... what does ";" signify ??
PRINT CHR$(218);: FOR x = 1 TO columns: PRINT STRING$(max_width(x), CHR$(196)) + CHR$(194);: NEXT: LOCATE , POS(0) - 1: PRINT CHR$(191);: PRINT

Thank you,

Mike
Title: Re: Need Help to Understand Code
Post by: Petr on February 07, 2019, 08:13:16 am
The IF value THEN condition means that the command executes if the variable has a value. So not specifically just value 1 but, if is has value. So if is  not zero.

The semicolon for the print command means that the print should be stacked one line at a time without indenting. If is PRINT in row with a comma, it prints in the line with space. If the PRINT command ends with a semicolon, the next print will continue from the last print location.
PRINT alone start new line for print.
Title: Re: Need Help to Understand Code
Post by: FellippeHeitor on February 07, 2019, 08:13:54 am
DIM SHARED DB_Debug_Mode AS LONG: DB_Debug_Mode = 1
IF DB_Debug_Mode THEN PRINT "Columns:"; columns
- shouldn't the line say IF DB_DEBUG_MODE =1 THEN PRINT .....

Just to clear context to anyone else reading this, we're talking about http://www.qb64.org/wiki/SQL_Client

IF DB_Debug_Mode THEN is seen by QB64 as IF DB_Debug_Mode <> 0 THEN, that's why it works.

Quote
- What does the ".object" do ?? I don't understand this line
IF Database(DB_Selected).Object = 0
If you notice a few lines up in that example, Database() is DIMmed as DB_TYPE. That's a custom type defined in that program as:

Code: QB64: [Select]
  1. TYPE DB_TYPE
  2.     Object AS _OFFSET

So that's just a fancy way to do DIM SHARED Database(DB_Last) AS _OFFSET instead. No idea why Galleon would go that route.

Quote
- A ":" signifies end of command (more than one command on a line) .... what does ";" signify ??
PRINT CHR$(218);: FOR x = 1 TO columns: PRINT STRING$(max_width(x), CHR$(196)) + CHR$(194);: NEXT: LOCATE , POS(0) - 1: PRINT CHR$(191);: PRINT

A semicolon after a PRINT statement (only place where it's valid in code) is used to keep the cursor after the printed text instead of moving it to a new line.

Edit: Petr beat me to it by a few minutes as I typed this :-)
Title: Re: Need Help to Understand Code
Post by: MLambert on February 07, 2019, 05:56:42 pm
Hi Fellippe,

Many thanks for your help.

Mike
Title: Re: Need Help to Understand Code
Post by: MLambert on February 08, 2019, 01:04:51 am
I have another question ...

_OFFSET  is defined as

"_OFFSET (function) returns the memory offset of a variable"

What does this mean ??

Mike
Title: Re: Need Help to Understand Code
Post by: SMcNeill on February 08, 2019, 06:49:30 am
_OFFSET is the location of a variable in memory.

X = 3

X is the variable name.

3 is the value of the variable.

_OFFSET(X) is the location of X in memory.
Title: Re: Need Help to Understand Code
Post by: MLambert on February 08, 2019, 04:25:56 pm
Thank you,
Mike
Title: Re: Need Help to Understand Code
Post by: MLambert on February 08, 2019, 04:39:21 pm
Hi,

I don't understand, why would I use _OFFSET instead of x = "3" ?

Similarly with _MEM ...

Mike
Title: Re: Need Help to Understand Code
Post by: SMcNeill on February 08, 2019, 04:54:54 pm
Hi,

I don't understand, why would I use _OFFSET instead of x = "3" ?

Similarly with _MEM ...

Mike

Think of it as printing to a file.
OPEN "temp.txt" FOR OUTPUT AS #1
FOR i = 1 to 10
    PRINT #1, i * 2
NEXT

The resulting temp.txt data file would look like the following:
2
4
6
8
10
12
14
16
18
20

Now, what's the 3rd line in that file?  Saying it's "3" wouldn't be right, now would it?

To have any idea what the content is, we have to actually specify that we're looking at a specific LINE in the text file, which is this case, the value of the 3rd line is 6...

Many programs work with LOCATION (which is basically what an _OFFSET is), instead of a variable name itself.

Another way to think of it is to say x$ = "9876543210".   

Now, where is the "7" in that string?  It's in the 3rd position... OFFSET 3 steps to the right, from the start....



_OFFSET(X) is the location of X in memory.
X is the variable/value it.



MyCar is a Ford.  It's parked in MyDriveway. 

In this case:

MyCar$ = "Ford"
_OFFSET(MyCar$) = "MyDriveway"

It's the difference of WHAT is it, verses WHERE is it.
Title: Re: Need Help to Understand Code
Post by: MLambert on February 09, 2019, 05:55:33 pm
Many thks ... but still not convinced.

Using INSTR or Arrays and Indexes or MID$ .. I can still perform the same calcs.

I think I will have to have a lie down and digest what you have said.

_offset 3 .... X$(3)  .. same thing ??

redim as _OFFSET ... dim x(10) .. same thing ??

Mike
Title: Re: Need Help to Understand Code
Post by: bplus on February 09, 2019, 08:10:05 pm
Hi MLambert,

Do you know what a pointer is in computer jargon?

All variables names and values are stored in computer memory. Pointers point to these addresses. The Basic Language manages all the address access to these values "under the hood". But you can have direct access to these in order to do some crucial calculations really fast like you would need with DB, managing huge amounts of data. As I understand it an _OFFSET is a memory pointer.
Title: Re: Need Help to Understand Code
Post by: Pete on February 09, 2019, 11:18:46 pm
Rob (Galleon) wrote the original MySQL code examples. He doesn't participate in the project (his project btw) anymore. Did you see his entry in the WIKI?

https://www.qb64.org/wiki/SQL_Client

Pete
Title: Re: Need Help to Understand Code
Post by: MLambert on February 10, 2019, 03:30:05 am
Hi ,

I was brought up on assembler .. so I understand pointers. I appreciate using _MEM for speed but it is interesting that Pete mentioned the SQL.
I have been plodding my way thru' this code.
This code caused me headaches trying to work out _MEM and redims _OFFSET, BYVAL   etc and the result was this current topic.
The _MEM caused me to think that to access SQL variables and selects, I had to know the memory locations where SQL would store some detail.

_MEM(_MEMGET(mem_mysql_row, mem_mysql_row.OFFSET + (x - 1) * LEN(an_offset%&), _OFFSET), length) .....

If the program had been originally written with some comments and not try to cram everything onto 1 line then maybe it would have been easier.

Again... thks for your help

Mike
Title: Re: Need Help to Understand Code
Post by: Pete on February 10, 2019, 04:56:46 am
Mike, I feel your pain.

Just for some history, the guy who wrote that MySQL code in the wiki is the one and only original developer of this language. He stayed current with this (his) project up until a couple of years ago. For 10 years, he worked solely on taking QB64 from an idea, to a nearly 100% QuickBASIC language, and then beyond to a GL and cross platform language. Of course, QB64 is a c++ translator, rather than a language that converts existing code to machine language, but still, quite an accomplishment for a single individual.... who was married, employed, and had a kid on the way. Anyway. long story longer.... yeah, no comments. Rob and I had that in common. I had worked on several office programs in QuickBASIC, which I consolidated into a single 80,000+ QB64 program. Because of how fast I needed  them done and the amount of work it was for a single person, I didn't comment anything, either. I actually used all caps, didn't indent, and used single letter variables, too. Well, that was to save memory in QuickBASIC but I did not change them when I converted over to 64. Anyway, if anyone had to read my code, they would chop off a foot and hop off a cliff before they were 10,000 line into it. So yes, I feel your pain when trying to digest this MySQL stuff, as presented.

I wish I was in a position to help, but I never needed MySQL. I just set up my own database structure and I never needed it online. I believe the reason why you haven't had more help is because most the other programmers I know who frequent these boards don't have any MySQL projects, either. At best maybe I just Murphy'd Law'd that and someone else will now come forward.

Best of luck with what you have managed to figure out so far. If you come up with a working model, I wouldn't blame you if you took it and ran but if you're inclined to post it here for others, will see if Bill will also place it in the "Library" so others can find their way through such a project in the future.

Pete
Title: Re: Need Help to Understand Code
Post by: MLambert on February 10, 2019, 10:06:35 pm
Hi Pete,

Thank you very much for the background. I too have worked all day and night to get the work done .... but I have always documented as I went .. and indented because I new that one day I would have to read it again myself. I am 70 now and writing a statistical package for my son-in-law ( a real nice person else I wouldn't bother).

I too have been using my own home grown database but I have not written the .. add a new key .. logic. I.e. database is up and running, all keys setup and everything working ... but now I need to insert a new row in the 'middle' of the table....  I thought I would try MySQL first .. also because it will give the application growth and support. ... I may slip off the planet soon ....

The database is big .. 5 billion records and growing at  500,000 per month now. It takes 14 hours to perform calculations but I am re-writing the basic methodology and should just take 20-30 seconds and I believe I can get this faster.

Regards,

Mike
Title: Re: Need Help to Understand Code
Post by: Pete on February 10, 2019, 10:16:20 pm
I'm in my 60s and now I do comment, spell out descriptive variable names, and indent. I really miss the "old" days... when I wasn't so damn old!

Mt database stuff was probably around 50,000 records, so we are miles apart in this area. You may want to start up a discussion with Steve, just on managing techniques. I don't think he has worked with MySQL, but he has worked on some commercial billion record systems.

Pete
Title: Re: Need Help to Understand Code
Post by: SMcNeill on February 10, 2019, 11:14:20 pm
MySQL experience is effectively zip with regards to trying to use it with QB64.  The only times I’ve ever had to work with SQL was for localized database access, so I’ve never needed to sort out online query information/protocols and such.  Much of my database work (when I was getting paid to do it), was written back in the day with DBASE IV or FoxPro 2.0 (and higher), and I’ve even written converters for DBF files so we can use them easily in QB64.  https://www.qb64.org/forum/index.php?topic=64.msg303#msg303

Unfortunately, those aren’t what you’re looking for here, so I’ve been mostly silent on this subject, hoping someone with more SQL/QB64 integration experience could help answer your questions.  ;)
Title: Re: Need Help to Understand Code
Post by: TempodiBasic on February 11, 2019, 08:25:23 am
Hi
on first I attach the files to work with MySQL  but I got little fortune and bad results...for my actual knowledge of mySQL I think

on second you must correct the code in the example in Wiki...
I'm expert about eating letters on typing so IMHO in the last row before END of the first example there is an "n" less than it should be

Quote
mysql_close con

in the example you can see that it is DIMmed conn and not con  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Need Help to Understand Code
Post by: MLambert on February 11, 2019, 09:15:10 pm
Hi All,

I have been working thru' mysql in wiki and found that it is a very strong piece of code.

It is very hard to read .. but plodding my way thru'.

I have been able to use it ... but at the moment I am checking error return code e.g. select a unique key ... what error return if not found.

I have had help from Fellippe and Juanjogomez

If anyone wants some detail on how to use it just let me know.

When I am finished I will post all of the code in this forum.

By the way I did not know mysql until I started this work ... it is pretty simple and logical. For the clever bits just google.

Mike
Title: Re: Need Help to Understand Code
Post by: TempodiBasic on February 17, 2019, 12:50:13 pm
It will be fantastic if in wiki the link mysql.dll was working!
But I have no original file attached to that link, only my downloaded version libmysql.dll from SQL website!

Long life to QB64! And to its contributors...
Title: Re: Need Help to Understand Code
Post by: Juanjogomez on February 17, 2019, 02:43:24 pm

Hi,
I do not use the error codes.
When you search for a data using a SELECT, the program returns the data in an array of rows or columns. If the rows are 0, you have not found any data. It's the first thing I check every time I do a search.
Regards
Title: Re: Need Help to Understand Code
Post by: MLambert on March 28, 2019, 07:12:11 pm
Hi  Juanjogomez

 When you check for errors ... would you pls show me your code..

Mike