Doe MaxIde Concatenation

BlitzMax Forums/BlitzMax Programming/Doe MaxIde Concatenation

Banshee(Posted 2008) [#1]
I've got some realy heavy duty SQL stuff to do in Blitz, and as Blitz doesn't have a closing brace at the end of each line, [ ie: var myString:TString; ] i'm wondering if the editor has concatenation? I've never found it if so! The docs and a search of the forum havn't yielded answers so I thought i'd ask out here.

The only other way for me to keep these SQL statements legible is to buld them up over multiple lines, ie:

q$="SELECT FROM"
   q$=q$+"servers as s, "
   q$=q$+"racers as r, "
   etc


This would result in impaired performance in runtime aswell as being far from ideal. I'm already using, I dunno what to call it, like a preg_replace type thingy with Bruce's excellent MySQL module ( prepared Query's and setString method ) but as this project gets more convoluted i'm concerned the code will become unreadable in Blitz.

Thank you for any assistance.


ImaginaryHuman(Posted 2008) [#2]
Put a ... on the end of the line and then carry on on the next line.


GfK(Posted 2008) [#3]
Put a ... on the end of the line and then carry on on the next line.
Its just ..


ziggy(Posted 2008) [#4]
the character .. does the job

q$="SELECT FROM" + ..
   "servers as s, "  + ..
   "racers as r, "


If I'm not wrong, this is calculated at compile time. (check the assembler generated).

confirmed, the generated assembler has only one string constant, that looks like this:
	dd	_bbStringClass
	dd	2147483647
	dd	38
	dw	83,69,76,69,67,84,32,70,82,79,77,115,101,114,118,101
	dw	114,115,32,97,115,32,115,44,32,114,97,99,101,114,115,32
	dw	97,115,32,114,44,32


you can see it generates a single string of 38 chars (see third mnemonic, wich indicates the length in double words (UTF) of the string).


Banshee(Posted 2008) [#5]
Ah thank you, I had not persevered enough when dealing with strings...

.prepare("SELECT FROM"+..
"servers as s, "+..
"racers as r,"+..
etc

Thank you for your assistance.


therevills(Posted 2008) [#6]
BTW You can use it in for any command, for example:

IF (x = y AND y = z) ..
   OR (y = a AND a = b) ..
      THEN
         z = b
END IF


Very useful when you have got a huge if statement!


Banshee(Posted 2008) [#7]
aye, whilst i'm at it with the Blitz fundamentals (it's always the basic stuff that confuses me as I switch between languages a lot, that plus i'm thick), i've done this before but it's eluding me atm...

Can anyone advise me please of the way to check if a binary bit is set to true in a number, so if I was to check bit two of an TInteger....

if myInt=%0000100 where 0 could be on or off

My memory tells me I do this with AND somehow, but I cant get it to compile :/

Thank you in advance


GfK(Posted 2008) [#8]
Don't quite understand how you've worded the question, but this should help
If myInt & %00000100
  'stuff
EndIf



Banshee(Posted 2008) [#9]
aha, I >think< I have it

if myInt&%100

:) soz for being a moron, I was born this way before I continued to develop into even more of a muppet

EDIT: Oh cheers Gfk, cross posted, but nice to know what I did is actually right


GfK(Posted 2008) [#10]
Yeah, you don't need all the leading zeros - personally I put them in for clarity.


Grey Alien(Posted 2008) [#11]
Yeah I find .. useful in declaring large arrays with preset values or very long if statements.


Banshee(Posted 2008) [#12]
OK there is something I have always found frustrating with BlitzMax and I wonder if there is a solution. I tend to work with a number of source files and consequently when I compile I first have to highlight either the master file or the output window, otherwise my include will try to compile as if it is the raw source.

Is there a way to specify what the 'parent' or 'master' file is to the compiler, so that if i've got a few dozen odd includes open I dont have to go hunting for the tab of the master file before I compile?

I've always found that annoying, it would be great if there was a compiler hook like, CompileFile "masterFile.bmx"

Thank you


Brucey(Posted 2008) [#13]
Open the file you want to be the "master". Choose, Program -> Lock Build File.

:-)


Banshee(Posted 2008) [#14]
Oh my, as easy as that!

All this time i've been making my life hard for myself.

Thank you Brucey! *hugs*

Now let me see, whilst i've got the attention of my betters...

When i'm returning a result from your MySQL module in my previous project I analysed the results based upon column number. This was fine for the purpose, but my current project is more complicated and i'd like to read the results off by field name. Can your module handle this?

Out of curiosity also, i'm used to using DB_DataObjects in php where you can assemble a query in a very OOP way, ie

<?php
$myObject = new myTableClass();
$myObject->playerName="Becky";
$myObject->find();
while ( $myObject->fetch() ){
   //$myObject contains any table row with player name of Becky each cycle
}


Is there a module to handle access a similar way? I'm just curious really as i'm more than happy building queeries manually.


tonyg(Posted 2008) [#15]
... are you deliberately lining Brucey up to prove himself the most productive and learned BlitzMaxer?


Banshee(Posted 2008) [#16]
I'll take help from anyone who knows something I want the answer for, but it is Brucey I kinda expect is most likely to answer the above questions :P

He can't be that productive though, he posts too much on the forum to actually use BlitzMax...


Brucey(Posted 2008) [#17]
i'd like to read the results off by field name.


Where you would normally use record.GetInt(index), you can also use record.GetIntByName(name) - *should* work :-)

...i'm used to using DB_DataObjects in php... Is there a module to handle access a similar way?

Not currently.
Htbaa has done some work on something like that, and I've also considered it as a possibility at some point, but there's nothing more concrete at the moment.


Banshee(Posted 2008) [#18]
You're a star Brucey. Not a rich one, but a star all the same :P

EDIT: I should warn you, i'm considering using more of your modules (BaH.Locale, BaH.libcurlSSL, BaH.Random and BaH.Crypto) which could meen the deathnail of your free time if you intend to give support ! :P


Russell(Posted 2008) [#19]
Interestingly (or annoyingly, depending..), I don't believe the ".." line continuation feature is mentioned at all in the docs, which is probably why so many people don't know about it ;)

Russell


Brucey(Posted 2008) [#20]
which is probably why so many people don't know about it

You are right. I just looked over all the docs and couldn't find mention of it anywhere. A shame, considering how useful it is.

I should warn you, i'm considering using more of your modules...

Oh.... I guess I should start to free up some resources then ;-)

You can't really go wrong with BaH.Random. Simply replace BRL with BaH in the Import, and you are done. (Other than the small issue of BRL.Basic, which imports BRL.Retro, which itself imports BRL.Random - I say, don't import BRL.Basic. Retro is so... yesterday. :-)
The others... well... we'll see.


Htbaa(Posted 2008) [#21]
I'm still *working* on a ORM/ActiveRecord and QueryBuilder implementation. But haven't had a lot of time for it yet.

So far I can use my TQueryBuilder type to create simple INSERT, UPDATE, DELETE and SELECT queries. With my ActiveRecord implementation you can do something like:

Local obj:TTableBooks = TTableBooks(new TTableBooks.Find(100))
Local str:TDBString =  obj.GetColumn("author_name")
'Or
Print obj.GetColumnString('author_name')


But it still needs a lot of work. Currently date fields and blobs aren't supported yet. Perhaps the coming 2 weeks I have some more time for it.


Banshee(Posted 2008) [#22]
I'm using BRL.Retro eeeep! But dont worry Brucey, if something is complex I usually don't have any issues figuring it out. It's only the really simple stuff that leaves me totally dumbfounded :)


big10p(Posted 2008) [#23]
How about requiring all statements in super strict mode be terminated with a semicolon. This would obviate the need for a special line break character, a la C/C++.

Just an idea.


Brucey(Posted 2008) [#24]
How about requiring all statements in super strict mode be terminated with a semicolon.

Gawd... are you volunteering to change my 100,000+ lines of source ?


big10p(Posted 2008) [#25]
Gawd... are you volunteering to change my 100,000+ lines of source ?
Er, no. Ok, maybe not have it work in super strict mode but have another mode that it works in - Uber Strict, or something. :P