i am creating backup using codigniter library "dbutil" and i have fields in my mysql database which having datatype bit when using below given code
public function run_backup()
{
$filename="MembersPro_database_$this->curr_date.sql";
$filepath="application/upload/DatabaseBackup/$filename";
$dbfilepath="MembersPro/application/upload/DatabaseBackup/$filename";
$prefs = array(
'ignore' => array(), // List of tables to omit from the backup
'format' => 'sql', // gzip, zip, txt
'filename' =>$filepath, // File name - NEEDED ONLY WITH ZIP FILES
'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file
'add_insert' => TRUE,
"foreign_key_checks" =>FALSE
/* 'newline' => "\n",*/
// Newline character used in backup file
);
$backup="CREATE DATABASE IF NOT EXISTS `MembersManagmentSystem`; USE `MembersManagmentSystem` ";
$backup .= $this->dbutil->backup($prefs);
if(!write_file($filepath, $backup))
{
echo "Error";die;
}
else
{
$_SESSION['sucessmsgbackup']="true";
}
$this->insert_into_datbase($filename,$dbfilepath);
redirect("ViewDatabaseBackup");
}
getting wrong output insert query
INSERT INTO `User` (`userId`, `userRoleId`,`userActive`, `userIsDelete`) VALUES ('20000046', '20001','1', '0');
in above given query "userActive" and "userIsDelete" fields having datatype "bit" and the query create by DbUtil library is treating it as string so i am getting warning error in mysql
"out of range column value"
Read Here Why you should not use BIT columns in MySQL
Issue reported Here in Github
Look into folder and modify core classes so that it will not escape, for example for mysqli driver
system/database/drivers/mysqli
https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/drivers/mysqli/mysqli_utility.php#L159
and find file mysqli_utility.php
locate line
$is_int[$i] = in_array(strtolower($field->type),
array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
TRUE);
Type numbers
numerics
-------------
BIT: 16
TINYINT: 1
BOOL: 1
SMALLINT: 2
MEDIUMINT: 9
INTEGER: 3
BIGINT: 8
SERIAL: 8
FLOAT: 4
DOUBLE: 5
DECIMAL: 246
NUMERIC: 246
FIXED: 246
and add your datatype to above array like below
$is_int[$i] = in_array($field->type,
array(16, 1, 2, 9, 3, 8),
TRUE);
Related
Hello i wish someone can help me it's my presentation tomorrow i would like to ask why does my values does not have lashes? ``` when i backup my database in php? i'm using codeigniter can someone please help me whenever i back up it it turns
INSERT INTO `discount` (`id`, `name`, `discount_percent`, `active`) VALUES (3, Student, 10, 1);
and it's giving me an error i think he want the value have lashes like this
INSERT INTO `discount` (`id`, `name`, `discount_percent`, `active`) VALUES ('3', 'Student', '10', '1');`
i tried the first one in my localhost but failed and the second one with lashes is successful so how can i backup with lashes?
my code is:
public function create()
{
// Load the DB utility class
$this->load->dbutil();
$test = date('YmdS-His');
// Backup your entire database and assign it to a variable
$config = array (
'format' => 'zip', // gzip, zip, txt
'filename' => 'bubblebee_'.$test.'_db.sql', // File name - NEEDED ONLY WITH ZIP FILES
'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file
'add_insert' => TRUE, // Whether to add INSERT data to backup file
'newline' => "\n", // Newline character used in backup file
'foreign_key_checks' => FALSE,
);
$backup =& $this->dbutil->backup($config);
$db_name ='bubblebee_'.$test.'.zip';
$this->load->helper('download');
force_download($db_name, $backup);
}
I am trying in Odoo v8 to create an invoice and its invoice lines using PHP.
However, when creating an invoice line I need to population invoice_line_tax_id which is a many2many field.
I have tried to read this page but I cannot figure it out : https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write
Here is how I create an invoice line
$result = $models->execute_kw($db, $uid, $password,
'account.invoice.line', 'create',
array(array(
'invoice_id'=> 15,
'product_id'=> 2,
'quantity'=> 1,
'name'=> 'Abonnement standard' ,
'price_unit' => 50 ,
'invoice_line_tax_id' => array( 0 , false , array( 2 ) )
)));
I have the following error in return :
string 'Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 75, in xmlrpc_return
result = openerp.http.dispatch_rpc(service, method, params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
result = dispatch(method, params)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
res = fn(db, uid, *params)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", li'... (length=2004)
If I just put the invoice_line_tax_id this way :
'invoice_line_tax_id' => array( 0 , false , 2 )
It works but no tax is inserted.
Any idea how to make this work ?
Thanks in advance.
For me, it worked this way:
'invoice_line_tax_id'=>array(array(4, $tax_id,false))
I used 4 option because the tax is already created.
I think the other array is necessary because in documentation said:
This format is a list of triplets executed sequentially
For those (like me) who struggle with odoo 10 :
Assuming your tax_id 1 exist in account_tax, correct syntax is invoice_line_tax_ids (note the final s) :
'invoice_line_tax_ids'=> [[4,[1],false]]
I have a problem with the case of a column name in Doctrine version 1.1.0.
I have a record (entity) with this definition:
abstract class BaseProductsXsell extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('products_xsell');
$this->hasColumn('ID', 'integer', 4, array('type' => 'integer', 'length' => 4, 'primary' => true, 'autoincrement' => true));
$this->hasColumn('products_id', 'integer', 4, array('type' => 'integer', 'length' => 4, 'unsigned' => 1, 'default' => '1', 'notnull' => true));
// and so on...
}
}
In the MySQL database table the column name of "ID" is upper case, too.
But when I try to fetch the column names after a query with this:
$query = Doctrine_Query::create()->select('m.*')->from("ProductsXsell m");
$collection = $query->execute();
$columns = $collection->getTable()->getColumnNames();
print_r($columns);
The output looks like this:
Array
(
[0] => id
[1] => products_id
...
)
I have not set the case attribute of the doctrine connection anywhere, so it should be the default value (Doctrine::CASE_NATURAL).
This results in the following error:
Fatal error: Uncaught exception 'Doctrine_Record_UnknownPropertyException' with message 'Unknown record property / related component "id" on "ProductsXsell"' in /opt/hocatec/bin/libs/Doctrine/Doctrine/Record/Filter/Standard.php:55
Stack trace:
#0 /opt/hocatec/bin/libs/Doctrine/Doctrine/Record.php(1282): Doctrine_Record_Filter_Standard->filterGet(Object(ProductsXsell), 'id')
#1 /opt/hocatec/bin/libs/Doctrine/Doctrine/Record.php(1240): Doctrine_Record->_get('id', true)
#2 /opt/hocatec/bin/libs/Doctrine/Doctrine/Access.php(117): Doctrine_Record->get('id')
#3 /opt/hocatec/bin/models/HocaSync.php(368): Doctrine_Access->offsetGet('id')
The name of the field that you want to select from your database must to be the same that you defined in your model. Is case sensitive.
You can read more about this here. The first part talk about "Columns" and explain that.
One problem with database compatibility is that many databases differ
in their behavior of how the result set of a query is returned. MySQL
leaves the field names unchanged, which means if you issue a query of
the form "SELECT myField FROM ..." then the result set will contain
the field myField.
Unfortunately, this is just the way MySQL and some other databases do
it. Postgres for example returns all field names in lowercase whilst
Oracle returns all field names in uppercase. “So what? In what way
does this influence me when using Doctrine?”, you may ask.
Fortunately, you don’t have to bother about that issue at all.
Doctrine takes care of this problem transparently. That means if you
define a derived Record class and define a field called myField you
will always access it through $record->myField (or $record['myField'],
whatever you prefer) no matter whether you’re using MySQL or Postgres
or Oracle etc.
In short: You can name your fields however you want, using
under_scores, camelCase or whatever you prefer.
NOTE: In Doctrine columns and column aliases are case sensitive. So when you are using columns in your DQL queries, the column/field names must match the case in your model definition.
What I want:
fetch some documents
for every document, set a field:
change it, if it exists
add it, if it doesn't
What I do:
// fresh data
print_r(iterator_to_array($collection->find()->limit(2)));
// query
$docs = $collection->find()->limit(2);
// fetch
foreach ( $docs AS $id => $doc ) {
// update
$collection->update(array('_id' => $doc['_id']), array(
'$set' => array(
'existing_field' => 'x',
'new_field' => 'y',
),
), array('multiple' => false));
}
// verify
print_r(iterator_to_array($collection->find()->limit(2)));
Why doesn't that do anything? The existing field isn't changed and the new field isn't added. Is the condition maybe wrong??
PS. The full code (with a lot of junk in between): http://pastebin.com/CNfCVxex
lines 33 - 37 -- fresh data
lines 63 - 76 -- query, fetch & update
lines 79 - 80 -- verify
Not familiar with the driver you are using here, but from your description you can achieve what you want in a single database hit, no need to fetch/loop/update..
The $set operator will insert or update a field depending on whether it exists or not.
db.Collection.update({}, { $set : { "myfield" : "x" } }, false, true)
The above would set the 'myfield' field in all documents in the collection to 'x', or if it already exists it would change the value to 'x'. Is that what you want to achieve?
I suspect you need to convert the string $doc['_id'] back to a MongoId by using new MongoId. See the example at the bottom of this page: http://www.php.net/manual/en/class.mongoid.php
In my model, I have a field called difficulty, but no matter what value i give it, a value of 1 is saved to the database.
I did a datadump on the model before I did a save() and this is what I see:
Array
(
[title] => testtt34
[serves] => 32
[prep_time] => 32
[cooking_time] => 32
[difficulty] => 4
)
But the sql query cakephp generated is this:
INSERT INTO `recipes` (`title`, `serves`, `prep_time`, `cooking_time`, `difficulty`, `modified`, `created`) VALUES ('testtt34', 32, 32, 32, 1, '2011-03-13 19:15:16', '2011-03-13 19:15:16')
What the heck? even though difficulty is clearly 4 in my datadump, the sql generated inserted difficulty = 1.
//Do some checking to make sure the data is from proper location
$this->data = Sanitize::clean($this->data);
$this->Recipe->data = $this->data;
//error checking
$this->pa($this->Recipe->data['Recipe']);
if ($this->Recipe->save())
{
//Blah do some stuff
}
Nevermind I accidentally set difficulty's type as TINYINT(1) meant to do TINYINT(3), well that fixed it. Very dumb mistake.