Well, I had an error report from a client of my ex-company. As I have an agreement with them to cover these situations I looked at it and thought "Oh no! The damn 'null null' error!".
So what was going on? Follow me:
I have a report that permits the client to find specific information about who receives referral fee over their contracts. So the client selects an user to search for and submits.
The ColdFusion template then search for referral fees this user receive in an referential table, which returns the contracts IDs. Then I search the contracts for details and loop over the contracts to mark which of them has already paid some referral to that user, do some formatting on the client's name and re-sort all data by paid, expiration date, finished date and then contract title.
To clarify, some code (I use "SELECT *" just for simplicity, don't do that on your code):
<cfquery datasource="dsn" name="qReferrals">So what the heck am I doing here? Well, I search for the referrals, verify if there is any, then I search for my contracts, creating two "to-be-filled" fields:
SELECT DISTINCT(contract_id) AS contract
FROM contract_referrals
WHERE user_id =
<cfqueryparam cfsqltype="cf_sql_integer" value="#form.user_id#" />
</cfquery>
<cfif qReferrals.recordCount>
<cfquery datasource="dsn" name="qContracts">
SELECT *,
0 AS paid,
'' AS clientName
FROM contract
WHERE contract_id IN
<cfqueryparam cfsqltype="cf_sql_integer" list="yes"
value="#valueList(qReferrals.contract)#" />
</cfquery>
</cfif>
0 AS paid,I thought the first one (paid) was being created as a NUMBER, a INT or TINYINT, I really doesn't care - but a damn number. The second field doesn't matter for this example. Alright? Let's go on:
'' AS clientName
<cfloop query="qContracts">Here I go through all the contracts found and search one by one for paid movements on the movement table. If I found one or more, I change the "paid" flag from 0 to 1. Pretty simple, uh?
<cfquery datasource="dsn" name="qPaid">
SELECT movement_id
FROM movement
WHERE contract_id = <cfqueryparam cfsqltype="cf_sql_integer"
value="#contract_id#" />
AND
movement_paid = 1
</cfquery>
<cfif qPaid.recordCount>
<cfset qContracts["paid"][currentRow] = 1 />
</cfif>
</cfloop>
<cfquery dbtype="query" name="qContracts">Again, pretty simple. I'm just reordering the query, using a query of queries and the already filled field that I created within the first run of the query.
SELECT * FROM qContracts ORDER BY
paid, expirationDate, finishedAt, title
</cfquery>
<cfquery datasource="dsn" name="qReferrals">And this is the code that works, but just 'cause the type of my data doesn't matter at all (I can sort from numeric or string types easily), but if that wasn't the case, I would be in trouble.
SELECT DISTINCT(contract_id) AS contract
FROM contract_referrals
WHERE user_id =
<cfqueryparam cfsqltype="cf_sql_integer" value="#form.user_id#" />
</cfquery>
<cfif qReferrals.recordCount>
<cfquery datasource="dsn" name="qContracts">
SELECT *,
'0' AS paid,
'' AS clientName
FROM contract
WHERE contract_id IN
<cfqueryparam cfsqltype="cf_sql_integer" list="yes"
value="#valueList(qReferrals.contract)#" />
</cfquery>
</cfif>
<cfloop query="qContracts">
<cfquery datasource="dsn" name="qPaid">
SELECT movement_id
FROM movement
WHERE contract_id = <cfqueryparam cfsqltype="cf_sql_integer"
value="#contract_id#" />
AND
movement_paid = 1
</cfquery>
<cfif qPaid.recordCount>
<cfset qContracts["paid"][currentRow] = "1" />
</cfif>
</cfloop>
<cfquery dbtype="query" name="qContracts">
SELECT * FROM qContracts ORDER BY
paid, expirationDate, finishedAt, title
</cfquery>
Labels: adobe, cfml, coldfusion, work
4 comments | Links to this text |
Jeffrey Zeldman wrote about the redesign of Happy Cog Studios web-site. This lead me through a really long line of thought.
As I pointed at previous post, design is important and ColdFusion being a programming language attached - since Macromedia's days - to the design world is a great thing.
That being said, I see ColdFusion development being fragmented these days. Some people argue for more programmatic, Object Oriented recurses. Some jumps to the boat to fight for more easy-to-use solutions. There's no consensus at the community.
To me is far more important to implement things quickly and easily - that meaning more webapps with less time - to make great systems and more money. As an entrepreneur, I'm interested in tools, tags and features for that. We have a handful of ideas but no time to implement all of them, even using CF, which we believe to be a RAD.
To accomplish that, Adobe should focus on two things:
I'm not saying that Adobe should forget all the great and advanced features. It has to be there and we like to know that, if we need, they'll be available without the need to spent more money. But the main focus should be RAD solutions, and the "Flex+ColdFusion" package seems to me as a sign that Adobe really understand things this way.
As a side note, Happy Cog new design is amazing. I wanted to do THAT with this web-site but, as you can see... I'm in lack of design skills to do so. =)
Labels: adobe, coldfusion, entrepeneur, flex, ide, rad, simplicity, work
Leave a comment | Links to this text |The numbers are huge:
This was made possible by a happy combination of many factors, like reduced taxes, increasing obligation of computer knowledge to apply for jobs, entertainment possibilities, etc. The bottom line is: more people here has internet access and computers. And that's fantastic for the Brazilian technology market.
Looking 10 years back, when I started, things were so different... I felt like I was begging for something or, better saying, felt like I was stealing something from them. "Internet is just fashion", "It'll pass by", "Wait, this amount of money for just a web-site?"... I heard a lot of that back in that days.
Now it's not SO different, but people look for the internet (and web, specially) and recognizes its importance, its influence over the crowds. And it reflects back to the computer and internet access market, and then back to companies like GrupoW, thanks god!
Being respected for what you do and getting some money for that is not a crime, is what every worker should have. And I'm glad we (internet builders, webdevelopers, designers, entrepreneurs and all people that work with internet related business) are finally starting to get it.
Labels: brasil, computer market, entrepeneur, internet business, respect, work
1 comment | Links to this text |