Hello,
I had a similar problem. I have an Install controller that executes a SQL
script in ordert to create the database.
What I have done is somethjing similar to:
uses('model'.DS.'connection_manager');
$db = ConnectionManager::getInstance();
$dataSource = $db->getDataSource('default');
// The to execute each SQL statement do:
$result = $dataSource->_execute($sql_statement');
if ($result) {
// success
} else {
// failure
}
I hope this helps you. Regards
2009/9/24 Stinkbug <[email protected]>
>
> I'm somewhat familiar with the schema stuff. However, the .sql file
> is a file that's going to be provided to us and not a file that will
> be generated by cake. Our .sql file isn't just about the schema, it
> could be large amounts of data manipulation using sql. So unless the
> schema stuff will execute a .sql file (rather than just generate it).
> I don't think it will work for us. That's why I was trying to get the
> code above to work.
>
> Any other thoughts?
>
> On Sep 23, 4:39 pm, Sam Sherlock <[email protected]> wrote:
> > I think you want to create a schemahttp://
> book.cakephp.org/view/735/Generating-and-using-Schema-files
> > - S
> >
> > 2009/9/23 Stinkbug <[email protected]>
> >
> >
> >
> > > I'm trying to execute a bunch of sql from a .sql file from the
> > > console. I was trying to use the query method inside the Model class,
> > > but I keep getting the following error.
> >
> > > Error: Missing database table 'models' for model 'Model'
> >
> > > Below is my code:
> >
> > > <?php
> > > App::import('Core', array('Model'));
> > > class UpgradeShell extends Shell {
> > > var $uses = array();
> >
> > > function main() {
> > > $filename = APP . 'config/sql/upgrade.sql';
> > > if (file_exists($filename)) {
> > > $handle = fopen($filename, "r");
> > > $sql = fread($handle, filesize($filename));
> > > fclose($handle);
> > > echo $sql;
> > > if ($sql) {
> > > //Model::query($sql);
> > > $model = new Model();
> > > //$model->query($sql);
> > > }
> > > }
> > > }
> >
> > > }
> > > ?>
> >
> > > When I try Model::query($sql);
> >
> > > I get the following error:
> > > Notice: Undefined property: UpgradeShell::$Model in C:\wamp\www\rx.com
> > > \app\vendors\shells\upgrade.php on line 13
> >
> > > Fatal error: Call to a member function query() on a non-object in C:
> > > \wamp\www\rx.com\app\vendors\shells\upgrade.php on line 13
> >
> > > I don't really need to specify models, I just want to execute the
> > > queries inside the .sql file.
> >
> >
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---