I have created a table with name person and added a column 'phone_number' using liquibase changeset. But now I want to add a default value for it. but it did not work, so far I have tried this:
<addDefaultValue columnName="phone_number"
defaultValue="+923331234567"
tableName="person"/>
and
<changeSet author="haseeb" id="20160413123500">
<update tableName="person">
<column name="phone_number" type="varchar(255)" defaultValue="+923331234567"/>
</update>
</changeSet>
and
<changeSet author="haseeb" id="20160413123501">
<update tableName="person">
<column name="phone_number" type="varchar(255)" value="+923331234567"/>
</update>
Can anyone point out where I did wrong and also would adding default value will add value to previously added rows?
try this
<addDefaultValue columnName="phone_number"
defaultValue="+923331234567"
tableName="person" columnDataType="varchar(255)"/>
Try this:
<changeSet author="haseeb" id="20160413123501">
<modifyDataType
columnName="phone_number"
newDataType="varchar(255)"
defaultValue="+923331234567"
tableName="person"/>
<comment>Change default value</comment>
</changeSet>
This is worked for expression:
- addDefaultValue:
tableName: RT_STAGE
columnName: CREATED_DATE
defaultValueComputed: now()
and this for boolean:
- addDefaultValue:
tableName: RT_STAGE
columnName: FINAL
defaultValueBoolean: false
Related
I want to be able to sort my column based on ascending or descending numbers. I don't totally understand the way to do this. The online documentation shows that a Menu must be added to the table, but how does the menu know to affect which column.
This is the current way I have my BluePrintJS table implemented. I want to make the values sortable ascending or descending for any column
<Table enableFocusedCell="true" numRows=10 class="bp3-html-table bp3-table-resize-horizontal">
<Column
columnHeaderCellRenderer={() => (
<ColumnHeaderCell name="Name" />
)}
cellRenderer={i => (array.data[i] ? (<Cell>{array.data[i].name}</Cell>)
: (<Cell />))
}
/>
<Column
columnHeaderCellRenderer={() => (
<ColumnHeaderCell name="Ins" />
)}
cellRenderer={i => (array.data[i] ? (<Cell>{array.data[i].ins}</Cell>
) : (<Cell />))
}
/>
</Table>
Magento 1.9
I want to create a new tab in System > Configuration.
In this tab, I need a group tab and in this group tab i want a textarea which is connected to a field of my database. If i edit my textarea, it will modify my database field too.
Look at this: https://prnt.sc/orwph1
I don't know how to connect my textarea with my db.. Create a new tab with a new group it's easy but connect it to the db..
Thanks!
let's assume you want a section that has 2 fields: multiselect, text area. In the multiselect you have all your customer and in the text are you get the modify to apply for a certain db field (related to the customer).
your system.xml should me something like this:
<config>
<tabs>
<admin_customTab_2 translate="label" module="sections">
<label>- TAB NAME -</label>
<sort_order>2</sort_order>
</admin_customTab_2>
</tabs>
<sections>
<customsection2 translate="label" module="sections">
<label>label name</label>
<tab>admin_customTab_2</tab>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<block translate="label">
<label>label name</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<block_customers>
<label>Select user</label>
<comment>user list</comment>
<frontend_type>multiselect</frontend_type>
<backend_model>sections/users</backend_model>
<source_model>sections/users</source_model> <!-- adding a source-model for the form's select -->
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</block_customers>
<block_textarea>
<label>changes to apply</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</block_textarea>
</fields>
</block>
</groups>
</customsection2>
</sections>
this is not enough for the configs, you need to tell Magento about the access control list (ACL) or admin-users will not see it. It is done in the config.xml
like this:
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<customsection2>
<title>Customer Changes?</title>
</customsection2>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
all is setted, but doing nothing but showing us the tabs and forms.
If you was brave enough you noticed a tag in the system.xml code up here,
<backend_model>sections/users</backend_model>
<source_model>sections/users</source_model> <!-- adding a source-model for the form's select -->
this tell magento that you are using a model relating to this form, where you can do operations.
So, in your Model's path create the (in this example) User.php
and here we go:
you want to extend your custom class with this one.
class Admin_Sections_Model_Users extends Mage_Core_Model_Config_Data
yes but we still didn't insert any data in the form.
You can do this by just adding a special function toOptionArray() :
public function toOptionArray()
{
$collections = Mage::getModel("customer/customer")->getCollection();
foreach ($collections as $colletion){
$user = Mage::getModel("customer/customer")->load($colletion->getId());
$array[] = array('value'=>$user->getEntityId(),'label'=>Mage::helper("sections")->__($user->getName()));
}
return $array ;
}
this will set ALL the customer's name into the multi-select form.
"yeah, nice.. I asked about the text-area"
before telling you how to get Data from Store Configs, you should know that there are 2 main methods for elaborating the form data:
public function _afterSave()
{}
public function _beforeSave()
{}
in there you can put all your code, no need to explain what is the difference between them.
in this function you can easy get the Data from Store Config by doing:
$text_area_string = Mage::getStoreConfig('customsection2/block/block_textarea');
"yeah nice... but my main problem is to save things in DB"
you can use whenever you prefer the Mage::getModel('') method , this can connect you to the database. Lets make an example; modify the 'is_active' field on 'customer_entity' table.
$customer = Mage::getModel("customer/customer")->load($customer_id);
$customer->setData("is_active",0);
$customer->save();
this field doesn't do really anything, it is just a very fast example.
This should let you do what you are aiming for.
If something sounds strange, please let me know!
currently i facing an issues which need initialize my token as any value 1st. However the token values will change when a new values received. Below is my code:
<form>
<init>
<set token="CH1_CHW_FLOW">0</set>
</init>
</form>
<search id="header">
<query>index="rtindex" Label="CH1" Order="12" |eval Value=round(Value,3) |stats latest(Value) as Value by ID2 |rename ID2 as Label | untable Label field name | xyseries field Label name</query>
<earliest>#d</earliest>
<latest>now</latest>
<preview>
<set token="FLOW_LPS">$result.CH1_CHW_FLOW_LPS$</set>
<set token="FLOW">$result.CH1_CHW_FLOW$</set>
<set token="COOLING_LOAD">$result.CH1_COOLING_LOAD$</set>
<set token="EFF">$result.CH1_EFF$</set>
</preview>
<table id="Chiller_1" border="1px solid black">
<tr><th>HEADER Details </th><th>Values</th></tr>
<tr><td>CHWF (USGPM)</td><td>$CH1_CHW_FLOW$</td></tr>
<tr><td>FLOW (LPS)</td><td>$CH1_CHW_FLOW_LPS$</td></tr>
<tr><td>COOLING LOAD</td><td>$CH1_COOLING_LOAD$</td></tr>
<tr><td>KW/Ton</td><td>$CH1_EFF$</td></tr>
</table>
However due to unknow reason i fail to initialize the value as Zero. It show me
$result.CH1_CHW_FLOW$ instead of zero. Please advise. Thank you very much.
The way to resolve it used eval:
if(isnull($result.fieldname$),0,$result.fieldname$)
How to skip CSV header line when using camel-beanio from apache?
My XML file for mapping look like this:
<beanio>
<record name="myRecord" class="my.package.MyConditionClass">
<field name="myField" position="1" />
<field name="mylist" position="2" collection="list" type ="string"/>
<segment name="conditions" class="my.package.MyConditionClass" nillable="true" collection="map" key="myKey">
<field name="myKey" position="2">
<field name="myValue" position="3">
</segment>
</record>
</beanio>
But to make my code run i must delete the first line (header line) manually. How do skip the header line automatically?
To read a CSV file and ignore the first header line, you can define the first field value of the header as comments of the CSV Stream
Example of CSV :
toto;tata;titi
product1;1;18
product2;2;36
product3;5;102
The mapping file :
<beanio ...
<stream name="dataStream" format="csv" >
<parser>
<property name="delimiter" value=";" />
<!-- ignore header line -->
<property name="comments" value="toto" />
</parser>
<record name="record" minOccurs="0" maxOccurs="unbounded" class="com.stackoverflow.Product" />
</stream>
</beanio>
Source : http://beanio.org/2.0/docs/reference/index.html#CSVStreamFormat
Another way will be to use camel-bindy in place of camel-beanio and the new option skipFirstLine (see https://camel.apache.org/components/latest/bindy-dataformat.html#_1_csvrecord)
Shortcut:
As soon as define BeanReader to read/process the records, use it's skip method with count 1 to skip the header.
e.g.
// Define Reader to process records
BeanReader beanReader = factory.createReader("STREAM",inputStreamReader);
// Skip First Record
beanReader.skip(1);
// Process rest of Stream
Object record;
do {
try {
record = beanReader.read();
}
catch (BeanReaderException e) {
e.printStackTrace();
}
} while(record !=null)
Refer http://beanio.org/2.0/docs/reference/index.html#TheMappingFile.
Skip method signature:
public int skip(int count) throws BeanReaderException;
I have an xml persisted in database something as follows:
<root available-locales="en_US" default-locale="en_US">
<dynamic-element name="fdemo-redirect-url" repeatable="false" dataType="string" indexType="" required="false" showLabel="true" type="text" width="25">
<meta-data locale="en_US">
<entry name="label"><![CDATA[fdemo-redirect-url]]></entry>
</meta-data>
</dynamic-element>
<dynamic-element name="close_button" repeatable="false" dataType="document-library" indexType="" required="false" showLabel="true" type="ddm-documentlibrary" fieldNamespace="ddm">
<meta-data locale="en_US">
<entry name="label"><![CDATA[close_button]]></entry>
</meta-data>
</dynamic-element>
....
I need to write a query which should replace an hyphen in name attribute of dynamic-element tag whose dataType attribute is html. I ended up creating the following query. But this works only for one tag at a time. I do not want to loop it using a procedure. Is there a way to tweak this query in such a way that this works for multiple dynamic-element tags?
UPDATE table_name
SET xsd = UpdateXML(
xsd,
'//dynamic-element[5]/#name',
CONCAT(
'name="',
REPLACE(ExtractValue(xsd, '//dynamic-element[5]/#name'), '-', '_'),
'"'))
WHERE ExtractValue(xsd, '//dynamic-element[5]/#dataType') = 'html';
Here in this above query only 5th dynamic-element tag is handled for all the rows.