Thursday, July 5, 2012

Part 3/3 -Running Apache Webserver, PHP, MySQL, Perl, CGI and ASP script without IIS on your Windows Box !!!


Edit the following sections in your Local website(or virtual directory) web.config file in the Microsoft .Net Framework folder. This will allow the .NET to parse asp files also in the same way as the aspx files:
<configuration>
<system.web>
        <compilation>
                <buildproviders>
                        <add extension=".asp" type="System.Web.Compilation.PageBuildProvider">
                </add></buildproviders>
        </compilation>
        <httphandlers>
                <add path="*.asp" type="System.Web.UI.PageHandlerFactory" validate="true" verb="*">
        </add></httphandlers>
</system.web>
</configuration>

Sunday, June 12, 2011

Transposing rows into columns fields with a dynamic SQL query. (Normalize the table)

I have always thought that it seemed to require an extreme number of ludicrously difficult SQL operations to do a simple transpose of rows into columns for repeating data tagged by a primary key. Many suggestions to fix this involve doing a cross tab, or exporting the data to excel and then constructing a pivot table, cube or a data pilot (or whatever it may be called in your application software).

Then you realise the pivot is not the answer as you have fields where it is not necessary to compute an aggregate function for the summary for a crosstab aka datapilot or pivot table.

Very often this is not required if you have a thoughtful DBA with correctly pre-designed Normalized DB tables.

However in the real world you will find that if you have gathered data say from an importing an excel spreadsheet, your tables will be often be in the de-normalized form.

Or the data in columns is dynamically collected through some web forms.
You might simply have forgotten to normalize the table before hand and realized your mistake when you started to write that complex Query. Now that the data is collected you can not dump it all and start over. You may want to do the normalization at the end to try and avoid inserting temporary nulls in your records.

Whatever the reason here is a a simple SQL statement construct, to re-construct a table by transposing the values non-primary key rows, grouping by the foreign key. Voila 3NF (third normal form).





SELECT ID,
MAX(CASE WHEN ItemNumber=1 THEN SomeFieldItemValue ELSE NULL END) AS [Item1],
MAX(CASE WHEN ItemNumber=2 THEN SomeFieldItemValue ELSE NULL END) AS [Item2],
MAX(CASE WHEN ItemNumber=3 THEN SomeFieldItemValue ELSE NULL END) AS [Item3],
MAX(CASE WHEN ItemNumber=4 THEN SomeFieldItemValue ELSE NULL END) AS [Item4],
MAX(CASE WHEN ItemNumber=5 THEN SomeFieldItemValue ELSE NULL END) AS [Item5]
FROM Table INTO NewTable
GROUP BY ID

EXAMPLE TABLE 1a: YourTable


ID (DEPARTMENT)



ItemNumber (Year)



SomeFieldItemValue (Sales Color Code)



1240



2009



Blue



1240



2010



Red



1240



2011



Red



3620



2009



Green



3620



2010



Green



3620



2011



Blue


Above is Your Table transformed to the New Table below

EXAMPLE TABLE 1b: newTable


ID (DEPARTMENT)



2009 (Item1)



2010 (Item2)



2011 (Item N)



1240



Blue



Red



Red



3620



Green



Green



Blue


Saturday, May 28, 2011

Eclipse compatible Makefile for IAR embedded workbench C project

Well here we come to the trickiest bit.
I enclose a sample self designed makefile for a HelloWorld type C program, which consists of multiple files, namely HelloWorld and HelloNextWorld...



###############################################################################
# Makefile for the C versions on windows
#
#
# NOTES : the CC and LD must be on the PATH environment variable
# this is because of a bug in the IAR EW 2.3x
# that does not allow whitespace in windows paths
# define the C_INCLUDE and XLINK_DFLTDIR environment variables as well
#
#set path=%PATH%;C:/Program Files/IAR Systems/ew23/430/bin
#set C_INCLUDE =C:/Program Files/IAR Systems/ew23/430/inc
#set XLINK_DFLTDIR=C:/Program Files/IAR Systems/ew23/430/lib

## General Flags
PROJECT = hellomsp430std
MCU = msp430
TARGET = $(PROJECT).d43

CC = icc430.exe
LD = xlink.exe

SRCS = $(wildcard *.c)
OBJECTS= $(patsubst %.c,%.r43, $(SRCS))

## Compile options
CFLAGS = -e -K -gA -s0 -RCODE -r0 -t8

## Linker flags
LDFLAGS = -rt -I"C:/Program Files/IAR Systems/ew23/430/lib" -f lnk430F1611.xcl
##

## Objects to be built


## Build
all: $(TARGET)

## compile

##$(PROJECT).r43: $(PROJECT).c
%.r43: %.c
$(CC) $(INCLUDES) $(CFLAGS) $<

##Link
$(TARGET): $(OBJECTS)
$(LD) $(LDFLAGS) $(OBJECTS) -o $(TARGET)

## Clean target
.PHONY: distclean
distclean: clean
@rm -f $(TARGET) $(PROJECT).lst $(PROJECT).map

.PHONY: clean
clean:
@rm -f $(OBJECTS)

###############################################################################

Tuesday, May 24, 2011

How to manually import an existing IAR Embedded Workbench project (.ewp)

Eclipse does not currently include a project import or export functionality for projects created with the Embedded Workbench .
Here are some steps that you might want to execute on a tried and tested project.

  1. Switch to the C/C++ perspective, and use File → New → C Project (use "C++ Project" if your project uses C++ in the compiler language settings).
  2. Project name: enter your project name here
  3. Un-check: Use default location. This will re-use existing files in your source folder.
  4. Location: enter your project location
  5. Project type: Executable: Empty Project
  6. Toolchains: IAR Toolchain for ARM - 6.x
  7. Click Next
  8. (optional) Modify the available build configurations to match the ones available in the EW project. By default, Eclipse will create a Debug and Release configuration.
  9. Click Next
  10. If your project is running on a device which is supported by Embedded Workbench, you can choose it now so that the project settings will be adjusted to fit. Otherwise, use the default settings.
  11. Finish

Adjusting project settings

  1. By defaults, Eclipse project options can be set per-configuration. Select "All configurations" in the project properties before the options are set to avoid setting them twice.
  2. Setup include paths: Project → Properties → IAR ARM C/C++ Compiler → Preprocessor → Additional include directories.
  3. Define preprocessor symbols, for example: IAR_LPC_1343_SK for some examples. Project → Properties → IAR ARM C/C++ Compiler → Preprocessor → Defined symbols.
  4. Set linker configuration file to match the EW project: Project → Properties → IAR ARM Linker → Configuration
  5. Manually set other build options (library configuration, etc.)
  6. Change between J-Link and Simulator, setup macro files: Run → Debug Configurations..
  7. Click OK
Note that unlike IAR Embedded Workbench, all of the build artifacts (list files, etc) will end up in the build output folder, which is in the project location and has the name of the currently-selected build configuration (e.g. "Debug"). Also, it could be necessary to manually refresh the build output folder to be able to see list and map files.

IAR Embedded workbench for MSP430 architecture and its integration with Eclipse

Well, this post will be first in a series to document the way to integrate IAR compiler and the Eclipse CDT environment.

IAR has already done this for many other architectures already, but how hard can it be anyway to integrate the most popular open source IDE with the World's best compiler/debugger and proceeded to make a fairly quick hash out of it(meaning I took triple the time I expected).

However their tried and tested beta plugin is already available on request provided you have the corresponding software and firmware. If like me however you don't have the requisite cross compilers and platforms but are working on the humble IAR EW MSP43. It can be done.

The steps shown here do not depend on any plugin. The end result will not allow debugging with the stand alone (or integrated- how lucky can you get?) C-spy debugger, but only the integration of projects into Eclipse for static analysis and use of 3rd party plugins like the super cool Unit and Integration tester Eclipse plugin I developed. Available for a measly $2500 dollars . This of course are my primary reasons for marrying the two software together.

Have a good time ! Remember back up all your work and if you mess up, its at your own risk !

Thursday, November 18, 2010

Part 2/3 -Running Apache Webserver, PHP, MySQL, Perl, CGI and ASP script without IIS on your Windows Box !!!

In order for ASP.net to work, we need to have a .NET Framework, this is normally pre-installed on all current MS machines. Otherwise, go ahead and download the DOTNETFX framework from Microsoft .NET

In my setup I used Microsoft .NET Framework Version: 2.0, but I suppose any version would be compatible.

Now install mod-aspdotnet for Apache HTTP Server 2.2.X where X is the number of my version. Generally forward and backward compatible through all X. At least I had no problems :)

Click on Browse and navigate your way to install at location folder C:\wamp\bin\apache\apache2.2.X where X is the number associated with your Apache version. Continue installation till finished successfully.


After opening the Apache httpd.conf file, we will add a line to enable the file httpd-aspdotnet.conf, and the best place is right after Virtual Hosts.


# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
# ASP.net
Include conf/extra/httpd-aspdotnet.conf


Now create a new file called httpd-aspdotnet.conf which is saved in folder C:\wamp\bin\apache\apache2.2.X\conf\extra where X is the number associated with your Apache version

# Load asp.net module
LoadModule aspdotnet_module "modules/mod_aspdotnet.so"

# Set asp.net extensions
AddHandler asp.net asp asax ascx ashx asmx aspx axd config cs csproj licx rem resources resx soap vb vbproj vsdisco webinfo

<IfModule mod_aspdotnet.cpp>
# Mount the ASP.NET /ASP application
AspNetMount /ASP "C:/wamp/www/ASP"

# Map all requests for /ASP to the application files
Alias /ASP "C:/wamp/www/ASP"

# Allow asp.net scripts to be executed in the /ASP folder
<Directory "C:/wamp/www/ASP">
# Set asp.net options
Options Indexes FollowSymLinks Includes +ExecCGI
# Set asp.net permissions
Order allow,deny
Allow from all
# Set asp.net default index page to .aspx and .htm
DirectoryIndex index.aspx index.htm
</Directory>

# Set aspnet_client files to serve the client-side helper scripts.
AliasMatch /aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*) "C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"
<Directory "C:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles">
Options FollowSymlinks
Order allow,deny
Allow from all
</Directory>
</IfModule>



Create a folder inside folder C:\wamp\www and here we have folder ASP. Under this subfolder

Now create a new text file hello.aspx
<%@ page LANGUAGE="VB" %>
<html> <head>
<body>
<center>
<% Dim I as Integer
For I = 0 to 7 %>
<font size="<%=I%>"> Hello, world!</font> <br>
<% Next %>
</center>
</body>
</html>


On running the ASP dotnetfx file from our localhost. A simple hello world output is generated through ASP without IIS

Ok. Go ahead and experiment. This however is the end of this little tutorial.

Part 1/3- Running Apache Webserver, PHP, MySQL, Perl, CGI and ASP script without IIS on your Windows Box !!!

What you’ll need for this install:
1. WampServer ( Windows Apache Mysql and PHP)
2. ActivePerl

Installing the WAMPServer setup is a quick and easy Apache webserver with PHP support and MySQL on windows.
Installing the Active perl setup in the c:wamp/bin/perl. This will set up a similar structure keeping the files separate, just like it is for php,mySql and Apache folders.

Now you’ll need to install a few extras …
From a command shell
Program Files -> Run -> cmd

cd\perl\bin
ppm

From the Packages select DBI as well as DBD-mysql if not installed and install these.

Now you’ve set up Perl with the extra packages you need its time to tell Apache what to do with .cgi files..
Click the little WampServer icon in your taskbar go up to config files and click on httpd.conf
You’ll want to add in section #cgi Options +ExecCGI

<Directory "cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>



somewhere around “Options Indexes FollowSymLinks”
you’ll also want to add in further down …
AddHandler cgi-script .cgi .pl

Restart Apache (click the icon .. and restart all or just … apache -> restart) … and you should be up and running

you need to create 2 files inside a new folder under www directory of wamp :acgi_form.html
backaction.cgi

Then run the acgi_form.html under wamp server.
Example file :
Create a file named acgi_form.html


<html>
<head>
<title></title>
</head>
<body>
<form action="backaction.cgi" method="GET">
<p>What is your favorite color?
<input name="favcolor" /></p>
<input type=submit value="Send form" />
</form>
</body>
</html>






Create a file named backaction.cgi
#!C:\wamp\bin\Perl\bin\perl.exe

use 5.010;
use CGI;

use strict;
use warnings;

my $q = CGI->new();
say $q->header(), $q->start_html();

say "<h1>Parameters</h1>";

for my $param ($q->param()) {
my $safe_param = $q->escapeHTML($param);

say "<p><strong>$safe_param</strong>: ";

for my $value ($q->param($param)) {
say $q->escapeHTML($value);
}
say '</p>';
}

say $q->end_html();

then , run the wamp server ,
and open the cgi_form.html
( for example : http://localhost/acgi_form.html )

oops, now you may see a 403 Forbidden message like this

Forbidden

You don't have permission to access /backaction.cgi on this server.

Whoops ... thats right. You have to put the script into the cgi-bin.
The ScriptAlias directs all scripts to be found in the /cgi-bin/

also change <form action="backaction.cgi" to <form action="/cgi-bin/backaction.cgi"

Now when you submit your personal favorite color the cgi or perl script will spit back the parameters at you.

Ok, this wraps up part 1 of the installation. In the next round we will learn how to get ASP.NET up and running without IIS.
Take a break and come again soon :)