<?php

/**
 * Database access adapter for ADOdb library
 *
 * @note CURRENT IMPLEMENTATION DOES NOT SUPPORT READING LAST INSERT ID FROM SEQUENCE
 * @version DR1.4.2
 */
class ADOdbAdapter extends DBAdapter {



	protected $ado;
	protected $dialect;
	protected $result;



	public function __construct(ADOConnection $ado, SQLDialect $dialect) {
		$this->ado = $ado;
		$this->dialect = $dialect;
		$this->result = new ArrayObject();
	}



	public function execute($sql, $sequenceName = null) {
		$this->result = new ArrayObject();
		$sql = trim($sql);
		if (preg_match('/^SELECT/i', $sql)) {
			$out = $this->ado->Execute($sql);
			if ($out) {
				while (!$out->EOF) {
					$this->result[] = $out->fields;
					$out->MoveNext();
				}
				$out->Close();
				return true;
			}
			return false;
		}
		$out = $this->ado->Execute($sql);
		if (!$out) {
			return false;
		}
		if (!$sequenceName or !preg_match('/^INSERT/i', $sql)) {
			return true;
		}
		return $this->pdo->Insert_ID();
	}



	public function getIterator() {
		return $this->result->getIterator();
	}



	public function getDialect() {
		return $this->dialect;
	}



} // class ADOdbAdapter

?>