PDA

View Full Version : splitting,filtering and loading into database


p0p0
02-10-2009, 02:48 AM
hye...i really need ur help...:confused:

i want to split this data: "123 Street of 'Maya' " into 3 columns

then i want to store the no.of the street,in this case;123 into local database.FYI i have created the local database using SQLite on my desktop.

then i want to filter the data using multiple checkboxs;for example:street,road name and so on.

can someone help me...

thanks a lot

wvxvw
02-10-2009, 09:24 AM
What do you want to appear in each column?

p0p0
02-11-2009, 01:24 AM
hye..ok,i will clear out to you what i need..:confused:

1--i have this data with me: 66.249.70.56 - - [31/Oct/2008:02:24:21 +0800] "GET /bppklms/index.php?cal_m=2&cal_y=1995 HTTP/1.1" 200 14400 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" . it is a string of log. u have helped me before but you split them using the (- -). i am thankful that u have helped me out..but can u show me how to split this string into 6 columns using the white space in the string.

the output should be like this:

in a datagrid with 6 columns:

first col:Log ID = 1
2nd col:IP Address = 66.249.70.56 -
3rd col:Date = - [31/Oct/2008:02:24:21 +0800]
4 col:Method = GET
5 col:Info = /bppklms/index.php?cal_m=2&cal_y=1995 HTTP/1.1
6 col: Status = 200

the last string can be ignored. FYI i can't alter the log because it will be uploaded from different sources.
i hope i'm not troubling u and u willing to help me with this one...

thansksss...........so much

wvxvw
02-11-2009, 09:42 AM
var str:String = "66.249.70.56 - - [31/Oct/2008:02:24:21 +0800] ";
str += "\"GET /bppklms/index.php?cal_m=2&cal_y=1995 HTTP/1.1\" ";
str += "200 14400 \"-\" \"Mozilla/5.0 (compatible; Googlebot/2.1; ";
str += "+http://www.google.com/bot.html)\"";
var re:RegExp = /(?P<ip>\d{1,3}(\.\d{1,3}){3})[^\[]+?(?P<date>\[[^\]]+?\])[^\w]+(?P<method>\w+?)\s(?P<info>[^"]+)[^\d]+?(?P<status>\d+)/gm
var result:Array = re.exec(str);
trace("IP:", result.ip);
trace("Date:", result.date);
trace("Method:", result.method);
trace("Info:", result.info);
trace("Status:", result.status);
But this is probably the longest regexp I've written ever :) And, considering that your info looks very much like Apache log and regexp in Flash isn't very fast... maybe you can do some preprocessing on the server? For instance, if you could separate log entries with pipes (|) you'd be able to use Array.split() instead of this regexp, simply because none of those parameters may ever contain pipe...

wvxvw
02-12-2009, 09:20 AM
OK... few things...
in the first input string you show you have quotes, in the string in another example you don't have them. So, the question is: do you really have quotes in the input string or was it a typo first time?
(\s\-\s\-\s) == " - - "
This means \s == " " and \- == "-"
If you will split the string on white spaces, then you'll get this:
array =>
[0] => 66.249.70.56
[1] => -
[2] => -
[3] => [31/Oct/2008:02:24:21
[4] => +0800]
[5] => "GET
[6] => /bppklms/index.php?cal_m=2&cal_y=1995 HTTP/1.1"
[7] => 200
[8] => 14400
[9] => "-"
[10] => "Mozilla/5.0
[11] => (compatible;
[12] => Googlebot/2.1;
[13] => +http://www.google.com/bot.html)"
which may be also OK, though you'll need to form the source array of your data provider in 2 steps. I.e. after you get this array, you'll do something like this:
dataProvider.addItem({ip: array[0], date: array[3] + array[4], .... });

wvxvw
02-13-2009, 01:50 AM
>> when there are two quotes in one string,it can't be recognized.what should i do??what are the codes to be added to the function?
Escape them?
var quote:String = "\"";

p0p0
02-13-2009, 07:00 AM
hye wvxvw..u had helped me a lot.thank u.now i'm able to share the knowledge with my friends..thanks..

but i still have to learn from you..i got this code: in attachment
i want to ask,if i want to suppress some of the columns or in other word; make some columns,for example column b and c invisible.

can it be done?it gets too crowded with unused columns.can u give me the full code how to do it.u have to assume that i know nothing.in this way i can learn from u.

thanks...

wvxvw
02-13-2009, 12:49 PM
I'd do it this way:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="applicationCompleteHandler()">
<mx:Script>
<![CDATA[
private function applicationCompleteHandler():void
{
var stringToSplit:String = "127.0.0.1 - - [15/Sep/2008:10:37:14 -0700]";
stringToSplit += " GET /bppklms/index.php?cal_m=2&cal_y=1995 HTTP/1.1 200"
stringToSplit += " 14400 - Mozilla/5.0 (compatible; Googlebot/2.1;"
stringToSplit += " +http://www.google.com/bot.html)";

var result:Array = stringToSplit.split(" ");
var logReader:LogReader = new LogReader();
logReader.ip = result[0];
logReader.date = result[3] + result[4];
logReader.method = result[5];
logReader.info = result[6] + result[7];
logReader.status = result[8];
sourceArray.push(logReader);
dp.refresh();
}
]]>
</mx:Script>
<mx:DataGrid width="963" height="341">
<mx:dataProvider>
<mx:ArrayCollection id="dp">
<mx:source>
<mx:Array id="sourceArray"/>
</mx:source>
</mx:ArrayCollection>
</mx:dataProvider>
<mx:columns>
<mx:DataGridColumn dataField="ip"/>
<mx:DataGridColumn dataField="date"/>
<mx:DataGridColumn dataField="method"/>
<mx:DataGridColumn dataField="info"/>
<mx:DataGridColumn dataField="status"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
package
{

/**
* LogReader class.
* @author wvxvw
* @langVersion 3.0
* @playerVersion 10.0.12.36
*/
public class LogReader
{
public var ip:String;
public var date:String;
public var method:String;
public var info:String;
public var status:String;

public function LogReader() { super(); }

}

}