Boolean results not displayed as expected

27 views
Skip to first unread message

J. Fink

unread,
Mar 8, 2011, 11:06:02 PM3/8/11
to PDO_4D
Using the CRUD database and files from the knowledge base link
(http://
kb.4d.com/search/assetid=76084), I queried for the Company.Name and
Company. Status fields (alpha 100 and Boolean, respectively). The
values for Status appear to be false or 0, but upon verification in
4D, the Status value for the companies “Benchmark Breakers and Coding
Crackers” is set to true. As this table and contents were created from
the create.php file, I haven’t done anything different to the table or
values.

Expected results:
Query Boolean Test - SELECT Name, status FROM Company
Company Name Status
Acme, Inc.
Alpha Beta
Aardvark Advocates
Benchmark Breakers 1
Coding Crackers 1

Actual results:
Query Boolean Test - SELECT Name, status FROM Company
Company Name Status
Acme, Inc.
Alpha Beta
Aardvark Advocates
Benchmark Breakers 0
Coding Crackers 0

Database results via Quick Report:
Name status
Acme, Inc. False
Alpha Beta False
Aardvark Advocates False
Benchmark Breakers True
Coding Crackers True

Of note, if the query is modified with the SQL function CAST(), the
results appear as expected.

Query Boolean Test - SELECT Name, CAST(status AS VARCHAR) AS Status
FROM Company

Company Name Status
Acme, Inc.
Alpha Beta
Aardvark Advocates
Benchmark Breakers true
Coding Crackers true

Web server: Apache 2.2.17, PHP 5.3.3 (MSVC9 (Visual C++ 2008)) on a
Windows Server 2003 Standard Edition Service Pack 2. I'm assuming the
version of PDO is 0.3 even though a phpinfo() shows 0.1 alpha as I
obtained the .dll from .zip link at http://forums.4d.fr/Post/FR/3549301/1/3601455#3601455

4D: v12.1 build 82774 on a Windows Server 2008 Standard Edition and
Windows Seven Business Edition, 64-bit

Alexandre Morgaut

unread,
Mar 9, 2011, 12:29:34 PM3/9/11
to PDO_4D
Can you give us your PHP Code

even if it is quite simple ;-)

It would be interesting

to test the result with the bindColumn() method

* http://www.php.net/manual/en/pdostatement.bindcolumn.php

Example

$stmt->bindColumn(1, $name, PDO::PARAM_STR);
$stmt->bindColumn(2, $statut, PDO::PARAM_BOOL);

J. Fink

unread,
Mar 9, 2011, 4:18:44 PM3/9/11
to pdo...@googlegroups.com
No such luck. The values that should display as True, displayed nothing.

$dsn = "4D:host=XXX.XXX.XXX.XXX;port=19812;dbname=crud;charset=UTF-8;";
$user = 'Administrator';
$pswd = 'test';
$db = new PDO($dsn, $user, $pswd);
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_TO_STRING);

$sql = "SELECT Name, status FROM Company";
$stmt = $db->prepare($sql);
$stmt->execute();

echo '<strong>Query Boolean Test</strong> - ' . $sql . '<br><br>';

//non-bound columns
$results_array = $stmt->fetchAll();

echo "<table><tr><th>Company Name</th><th>Status</th></tr>";
foreach($results_array as $result)
{
  echo "<tr><td>".$result['NAME']."</td><td>".$result['STATUS']."</td></tr>";
}
echo "<table>";

//let's try binding the columns
$sName = ""; $sStatus = "";
$stmt->bindColumn('NAME', $sName, PDO::PARAM_STR);
$stmt->bindColumn('STATUS', $sStatus, PDO::PARAM_BOOL);

echo "<table><tr><th>Company Name</th><th>Status</th></tr>";
while ($row = $stmt->fetch(PDO::FETCH_BOUND))
{
  echo "<tr><td>".$sName."</td><td>".$sStatus."</td></tr>";
}
echo "<table>";
3-9-2011_4-06-15 PM.pdf
Reply all
Reply to author
Forward
0 new messages