Assume having the following csv:
a,b,c
1,2,3
where a,b,c are column names and 1,2,3 are values.
Is it possible to load only columns a,b?
<loadUpdateData tableName="TABLE"
file="file.csv"
primaryKey="a">
<column name="a" header="a"/>
<column name="b" header="b"/>
</loadUpdateData>
This will generate an SQL error, because it will try to insert column c.
I am using MySQL.
Haven't tried it myself but looking at the code (for LoadDataChange) there seems to be an option to "skip" a column config:
if ("skip".equalsIgnoreCase(columnConfig.getType())) {
continue;
}
So maybe you can add a column config for 'c' and set its type to "skip":
<column name="c" header="c" type="skip" />
Related
I have a form with a series of checkboxes. The name of the checkboxes is name="groups[]".
<input type="checkbox" name="groups[]" value="value-1">
<input type="checkbox" name="groups[]" value="value-2">
<input type="checkbox" name="groups[]" value="value-3">
<input type="checkbox" name="groups[]" value="value-4">
I want to save the values submitted to a column named groups in a MySQL database. My Laravel update code is as follows:
$record->groups = $attributes['groups'];
$record->save();
I have also tried:
$record->groups = implode(',', $attributes['groups']);
$record->save();
Just in case it helps, the field details in the migration file is:
$table->set('groups', ['value-1','value-2','value-3','value-4'])->nullable();
The error receiving is:
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'groups' at row 1 (SQL: update `table` set `groups` = ["value-1","value-2"] where `id` = 1)
Is my update code incorrect for Laravel and Set columns?
I tried Googling a lot, but because the term set is used in regular update queries, I'm not getting helpful results.
Edit: Added Table Structure
Column
Type
id
bigint(20)
groups
set('value-1','value2','value-3','value-4')
Edit: Results of my attributes:
array: 1 [▼
"groups" => array:2 [▼
0 => "value-1"
1 => "value-2"
]
]
'''
It ends up that the correct method to update a set type column is to implode the array into a comma separated string. I thought I tried this earlier, but it's working now, not actually sure why it wasn't before and is now. Here is the working update:
$proposal->groups = implode(',', $attributes['groups']);
$proposal->save();
I'm working on migrating some codes from MSSQL to MySQL, but I don't know the equivalent of local-name()in MySQL.
The original MSSQL code is as followed:
with cte as (select convert(xml,'<Attributes>
<Map>
<entry key="trigger" value = "action">
<value>
<Map>
<entry key=" Processing">
<value>
<Boolean>true</Boolean>
</value>
</entry>
</Map>
</value>
</entry>
</Map>
</Attributes>') as attributes)
select entr.value('#key','nvarchar(100)') AS AttrKey
,entr.value('#value','nvarchar(500)') AS AttrValue
,HasValueElement.value('local-name(.)','nvarchar(100)') AS ValueType
FROM cte a1
cross apply a1.attributes.nodes(N'/Attributes/Map/entry') A(entr)
OUTER APPLY A.entr.nodes(N'value/*') B(HasValueElement)
The output is:
AttrKey ||AttrValue ||ValueType
Trigger ||Action ||Map
How we can apply similar to local-name() in MySQL to return the ValueType = "Map"? When I tried something like "//*[local-name()]" in MySQL, it returned error.
And what is the "." in "local-name(.)" meaning?
Really appreciate your support.
TIA
is it a bug?
when I use mybatis and mysql, a column name id permission_ids, I got null always.
but when I change it to permissions, it worked. Why?
SELECT
sys_role.id,
sys_role.role,
sys_role.description,
sys_role.permission_ids
FROM sys_role
WHERE id = #{id}
If you're using XML file:
you should have:
<select id="selectQuery" resultMap="selectMap">
SELECT
sys_role.id,
sys_role.role,
sys_role.description,
sys_role.permission_ids
FROM sys_role
WHERE id = #{id}
</select>
<resultMap id="selectMap" type="SysRole">
<id column="permission_ids" property="permissionIds">
<result ....//the rest columns to map to java properties in your model class "SysRole"
</resultMap>
That should work !
If not, as an alternative to your solution, you can use Alias instead of renaming the column "permission_ids":
SELECT
sys_role.id,
sys_role.role,
sys_role.description,
sys_role.permission_ids **as permissions**
FROM sys_role
WHERE id = #{id}
var result = from p in dc.People
join d in dc.Departments
on p.fk_dep_id equals d.pk_dep_id
select p;
return result.ToList();
The linq query above will select all People, together with the full name of the department they are assigned to. This result contains the Department data in an object "Department", which I can see when debugging.
However, when adding this result to a gridview, the joined data triggers an error:
"A field or property with the name "Department.name" was not found on the selected data source.
I tried doing the following in the Gridview:
<asp:BoudField DataField="Department.Name" HeaderText="Department" SortExpression="Department.Name" />
Any ideas on how to display such a "joined" columns in a Gridview, by using linq2sql data?
The DataField should be a property name of the object in the data source. You can't use complex expressions like that. For this you need the TemplateField:
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server"
Text="<%# (Eval("Department") as Department).Name %>" />
</ItemTemplate>
</asp:TemplateField>
I need further assistance with extracting records from XML and loading it into a SQL Server table.
I have this as my #xml:
<admin submitter_id="login0" effective_date="mm/dd/yyyy">
<rec effected_id="login1" adjustment="100.00" type="foo">
<reason reason_id="1" />
<reason reason_id="2" />
</rec>
<rec effected_id="login2" adjustment="50.00" type="bar">
<reason reason_id="3" />
</rec>
</admin>
I need this from a result set:
login0, login1, mm/dd/yyyy, 100.00, foo, 1
login0, login1, mm/dd/yyyy, 100.00, foo, 2
login0, login2, mm/dd/yyyy, 50.00, bar, 3
Does that make sense? The adjustment to the reason_id is one to many. I have figured out how to extract all the values except for the second line. I can only obtain the first reason_id and then it proceeds to the next record. I think this can be beaten with a CROSS APPLY but I cannot get it to work. Please help!
oh, I may also have received bogus XML. So if that's wrong, please tell me!
How about something like
DECLARE #Xml XML
SELECT #Xml = '<admin submitter_id="login0" effective_date="mm/dd/yyyy">
<rec effected_id="login1" adjustment="100.00" type="foo">
<reason reason_id="1" />
<reason reason_id="2" />
</rec>
<rec effected_id="login2" adjustment="50.00" type="bar">
<reason reason_id="3" />
</rec>
</admin>'
SELECT #Xml,
A2.B.value('(../../#submitter_id)[1]','VARCHAR(50)'),
A2.B.value('(../#effected_id)[1]','VARCHAR(50)'),
A2.B.value('(../../#effective_date)[1]','VARCHAR(50)'),
A2.B.value('(../#adjustment)[1]','FLOAT'),
A2.B.value('(../#type)[1]','VARCHAR(50)'),
A2.B.value('(#reason_id)[1]','INT')
FROM #XML.nodes('//admin/rec/reason') A2(B)
SQL Fiddle DEMO
Try to use this T-SQL code snippet:
SELECT
Submitter = #xml.value('(/admin/#submitter_id)[1]', 'varchar(50)'),
EffectedID = Rec.value('(#effected_id)[1]', 'varchar(50)'),
DateStamp = #xml.value('(/admin/#effective_date)[1]', 'varchar(50)'),
TypeID = Rec.value('(#type)[1]', 'varchar(50)'),
ReasonID = Reason.value('(#reason_id)[1]', 'int')
FROM
#xml.nodes('/admin/rec') AS Tbl(Rec)
CROSS APPLY
Rec.nodes('reason') AS T2(Reason)
It gives me an output of:
You need to have two nested lists of nodes - the first one grabs all the <rec> nodes from inside <admin>, while the second one iterates over all the <reason> nodes inside each of the <rec> nodes. That way, you can reliably extract all information from those two nested levels of subnodes, no matter how many subnodes there are on each level.