SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member Greywacke's Avatar
    Join Date
    Dec 2013
    Location
    Rietfontein, Pretoria
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation faulty regular expression for seconds extraction - but cannot see what is wrong... :S

    Hi there, in my site I have a console which optionally outputs any sql queries run, plus various debugging info. Nw when running the query which I want to see the timeout info of - the following snippet of script is used.
    The result being that the sql query's info is not always sent via xml. The following code attempts to parse the sql string, to get the line mentioning the time taken to process - saving that to rcnt. Then if match() does not return null, it is supposed to get the time taken in seconds. note the two lines in bold below. after this it is supposed to replace a %SEC% flag in the innerHTML of the topmost field (id cntf) in the data table.
    Code:
                        if (sql != undefined) {
                            var rcnt = sql.match(/^line [\d]+[\/a-z\. ]*[\d]+.[\d]+ seconds.$/mgi);
                            salert(sql);
                            salert(rcnt);
                            if (rcnt !== null) {
                                var ncnt = rcnt[0].match(/[\d]*.[\d]*/g);
                                document.getElementById("cntf").innerHTML.replace(/%SEC%/g,ncnt[0]);
                            }
                        }
    the value of sql is shown below, returned from ajax - followed by the value of rnct (which is shown to be null):
    '0' => "SELECT
    UPPER(SC.text_ServiceDescription) AS Service,
    GROUP_CONCAT(DISTINCT IF(
    R.bigint_ParentRegionID=0,
    R.text_RegionDescription,
    R1.text_RegionDescription
    ) SEPARATOR '
    ') AS Country,
    UPPER(IF(
    R.bigint_ParentRegionID!=0,
    R.text_RegionDescription,
    R0.text_RegionDescription
    )) AS Region,
    UPPER(S.text_SupplierName) AS Supplier,
    GROUP_CONCAT(DISTINCT UPPER(CASE S.smallint_SupplierStatus
    WHEN 0 THEN 'Premium'
    WHEN 1 THEN 'Paused'
    WHEN 2 THEN 'Trial'
    WHEN 3 THEN 'Inactive'
    WHEN 4 THEN 'Freemium'
    END) SEPARATOR '
    ') AS Status,
    GROUP_CONCAT(DISTINCT UPPER(IF (
    SC.bigint_PrimaryAttributeKey = 0 OR SA1.text_AttributeValue = NULL,
    'DEFAULT',
    SA1.text_AttributeValue
    )) SEPARATOR '
    ') AS Prim_Att_Val
    FROM
    4_servicesuppliers SS
    INNER JOIN 2_servicescatalogue SC ON (SS.bigint_ServiceID = SC.bigint_ServiceID)
    INNER JOIN 1_regions R ON (SS.bigint_RegionID = R.bigint_RegionID)
    INNER JOIN 5_suppliers S ON (SS.bigint_SupplierID = S.bigint_SupplierID)
    LEFT JOIN 3_serviceattributes SA0 ON (SC.bigint_PrimaryAttributeKey = SA0.bigint_AttributeID AND SC.bigint_ServiceID = SA0.bigint_AttributeServiceID)
    LEFT JOIN 3_serviceattributes SA1 ON (SA0.text_AttributeDescription = SA1.text_AttributeDescription AND SC.bigint_ServiceID = SA1.bigint_AttributeServiceID)
    LEFT JOIN 1_regions R0 ON (R.bigint_ParentRegionID = 0 AND R.bigint_RegionID = R0.bigint_ParentRegionID)
    LEFT JOIN 1_regions R1 ON (R.bigint_ParentRegionID != 0 AND R.bigint_ParentRegionID = R1.bigint_RegionID)
    LEFT JOIN 9_supplierattributes SA3 ON (S.bigint_SupplierID = SA3.bigint_SupplierID AND SC.bigint_ServiceID = SA3.bigint_ServiceID AND ((R.bigint_RegionID = SA3.bigint_RegionID OR R.bigint_ParentRegionID = SA3.bigint_RegionID) OR (R0.bigint_RegionID = SA3.bigint_RegionID OR R0.bigint_ParentRegionID = SA3.bigint_RegionID) OR (R1.bigint_RegionID = SA3.bigint_RegionID OR R1.bigint_ParentRegionID = SA3.bigint_RegionID)) AND SA1.bigint_AttributeID = SA3.bigint_AttributeID)
    LEFT JOIN 3_serviceattributes SA2 ON (SA3.bigint_AttributeID = SA2.bigint_AttributeID AND SC.bigint_ServiceID = SA2.bigint_AttributeServiceID)
    WHERE SA2.text_AttributeValue IS NULL
    GROUP BY `Service`, `Region`, `Supplier`
    ORDER BY `Service` ASC, `Region` ASC, `Supplier` ASC;



    $_SESSION =
    $_POST = Array
    (
    [orderby] => ORDER BY `Service` ASC, `Region` ASC, `Supplier` ASC
    [where] => WHERE
    [groupby] => GROUP BY `Service`, `Region`, `Supplier`
    [groupcnct] => ,`Country`,,,`Status`,`Prim_Att_Val`
    )

    Line 829 in /var/www/performatix.co/production/scripts/ajax_services.php executed in 0.089391946792603 seconds.
    "
    '0' ...
    However, I am struggling to match the bold, italic and underlined with regular expressions. What am I doing wrong here? 0o
    sincerely - Pierre.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Hi,

    So in other words, in this string:

    Code:
    Line 829 in /var/www/performatix.co/production/scripts/ajax_services.php executed in 0.089391946792603 seconds.
    you want to match:

    Code:
    0.089391946792603
    Is that correct?

    Is it just this one case you are trying to match, or is there a pattern (e.g. "{Line no} {file path} executed in {time} seconds.") whereby you are trying to get the time?

  3. #3
    SitePoint Member Greywacke's Avatar
    Join Date
    Dec 2013
    Location
    Rietfontein, Pretoria
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes pullo - it was just one case... i resolved it by making sure it was that line and specific ajax request then repaired the regex match as follows...
    issue was resolved by changing the regex matches and adjusting the javascript to:
    Code:
                        if (sql != undefined) {
                            var rcnt = sql.match(/(line 829[a-z\/_. ]+)[0-9]+\.[0-9]+/g);
                            if (sql.toLowerCase().indexOf('line 829')==-1) salert(sql);
                            //salert(rcnt);
                            if (rcnt !== null) {
                                var text = document.getElementById("cntf").innerHTML;
                                document.getElementById("cntf").innerHTML = text.replace(/%SEC%/g,rcnt[0]);
                            }
                        }

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Glad you got it sorted out.
    Thanks for taking the time to report back


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •