MyBatis Generator removes useGeneratedKeys="true" - generator

I'm using MyBatis Generator in Eclipse Helios (MyBatis Generator 1.3.1.201101032122)but every time I generate automatically the persistent classes the generator removes the attribute useGeneratedKeys="true".
So for example I have the tag in my AdresseMapper.xml. After I changed something in my db and I run 'Generate MyBatis Artifacts' this tag is overwritten and useGeneratedKey isn't there anymore...When I remove WARNING - #mbggenerated, there is a conflict between a new generated insert(without the attribute) and the old version...
Could you kindly help me? I didn't find anything in the official doc..
Many thanks
Fabio

The MyBatis Generator must know which column has generated keys. You can do that using the generatedKey tag inside the table tag.
Example:
<table tableName="adresse" alias="adresse">
<generatedKey column="id" sqlStatement="MySql" identity="true" />
</table>

Related

PHPStorm warnings on placeholders in WordPress plugin queries

I have a WordPress plugin that I am editing in PHPStorm. PHPStorm finds syntax errors on queries like this when the SQL dialect is set to MySQL:
$foo = $wpdb->get_var(
$wpdb->prepare(
'SELECT `foo` FROM `some_table` WHERE `id` = %d',
$bar
)
);
Specifically, it sees %d and complains with this message:
<expression> expected, got '%'
Of course, %d is a perfectly legitimate placeholder in WordPress queries. Is there a way to configure PHPStorm to accept this? Or do I have to disable all checks on SQL statements, as suggested in this answer?
Note that I am using PHPStorm EAP 8 (138.1751), and the same thing happens with other placeholders like %s.
This is now possible in PHPStorm 8, as explained by this post on the official PHPStorm blog:
Database Language Injection Configuration
To solve it:
Go to Tools > Databases
Make sure a regex matching the placeholders in question is in the list of custom parameters. By default, the list includes \%\w+, which will match %s, %d, etc.
Check the box labeled "Use in other language string literals"
PHPStorm will now correctly recognize placeholders like those used in WordPress.
Nope -- %d is not valid syntax from SQL point of view (ANY currently supported dialect). The WI-3672 and WI-2324 tickets are still valid.
But PhpStorm v8 now supports $var (if you could use it instead of % syntax) -- http://youtrack.jetbrains.com/issue/WI-2450
Since it's WordPress specific question, it's hard for me to give you any real suggestion (especially since I'm not using WordPress myself) excluding that one.
But generally speaking you could use native place holders supported by specific DB engine (check "Examples" section in http://php.net/manual/en/pdo.prepare.php):
unnamed ?
named :id
I just not sure if this can be applied to WordPress development.
P.S.
Generic is the new Keywords only dialect -- fall back to that if using proper SQL dialect shows to many warnings/errors (that are not actual errors).

Can I remove a namespace import from a linqpad query?

I am trying to run a linqpad query, but one of the default namespace imports has a type that is apparently shadowing the type I am trying to reference. System.Xml is one of the default imports in linqpad, but I rarely use it. Is it possible to remove that default namespace import, so I can use my own Formatting enum?
This isn't a direct answer to your immediate question, but you can can tell LINQPad which one you want Formatting to mean. In your query, press the F4 key and then under the Additional Namespace Imports tab you can add the following:
Formatting = Newtonsoft.Json.Formatting
This tells LINQPad to declare a using alias directive for your script. Note that you should not include the word using before the line, LINQPad handles theat for you.

XmlReaderParsingException: The start element with name <...> and namespace "http..." was unexpected

This is for BizTalk 2010. I am running into a very strange issue that I've not been able to find a solution either using my favorite search engine's results or elsewhere.
I added several SQL Server 2008 table schemas to BizTalk. Set up orchestration and mapping without any problems. BizTalk was able to use WCF_Custom SQL Adapter using XML/BTSAction to insert data to the SQL tables identified in the XML.
Some of those tables had data inserted just fine, except two. Both had the same error. The error was pulling from a third table's namespace. Here's the error in full -- notice that the namespace, ns, is for ns46:professionalAddendum as is expected, but somehow, somewhere, BizTalk is pulling a different namespace, ns35, from a different table:
Microsoft.ServiceModel.Channels.Common.XmlReaderParsingException: The start element with name "ClaimFilingIndicatorCode" and namespace "http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/professionalCOBAdjustmentsAncillary" was unexpected. Please ensure that your input XML conforms to the schema for the operation.
<ns2:Insert xmlns:ns2="http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/professionalAddendum">
<ns2:Rows>
<ns46:professionalAddendum xmlns:ns46="http://schemas.microsoft.com/Sql/2008/05/Types/Tables/dbo">
<ns46:uid_claim>1b8f20e9-0517-4f00-9ee2-99d5f04d1573</ns46:uid_claim>
ERROR>>>>> <ns35:ClaimFilingIndicatorCode xmlns:ns35="http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/professionalCOBAdjustmentsAncillary">17</ns35:ClaimFilingIndicatorCode>
<ns46:ClaimFrequencyTypeCode>1</ns46:ClaimFrequencyTypeCode>
<ns46:ProviderAcceptAssignmentCode>B</ns46:ProviderAcceptAssignmentCode>
<ns46:BenefitsAssignmentCertificationIndicator>Y</ns46:BenefitsAssignmentCertificationIndicator>
<ns46:ReleaseofCode>Y</ns46:ReleaseofCode>
<ns46:ProviderOrSupplierSignatureIndicator>N</ns46:ProviderOrSupplierSignatureIndicator>
</ns46:professionalAddendum>
</ns2:Rows>
</ns2:Insert>
Is there a way to fix this? Really weird.
Thanks all!
It's tough to know exactly what is going on without seeing your full schema, but I have seen it where the case of a table name changes somewhere, and then the corresponding namespace no longer matches.
For example:
http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/professionalAddendum
vs
http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/ProfessionalAddendum
I'm posting up what I found. The map and orchestration are both fine for the most part. There was a Scripting functoid in the mapper that used an inline XSLT to map from the source schema to the destination schema, and the offending namespace was in that XSLT code. When I changed the schema's tables, their corresponding namespace #s changed as well thus causing this problem to manifest itself. Having said that, I fixed it up to be flexible should the schema tables' namespace #s change again.
Problem solved. Now I got to fix up a few of those. :)
Thanks all for your help.

Is it possible to perform a MySQL query using Phing and set the value as a property?

I'm new to Phing.
I'd like to query a value in a MySQL database table, and have the value set as a property so that I can echo it out nicely to the screen.
I can see that there is a PDOSQLExecTask which would allow me to run some SQL, but I can't see how to set the returned value into a property?
The query I want to run is:
SELECT MAX(change_number)
FROM changelog;
I'd like it set into a property:
Can anyone shed any light please?
Thanks,
Chris
I have access to MySQL at command line, I went with the following solution. I'm sure it's not the best, if someone else can improve it please do!
<!-- What's the latest delta that's been applied to this deployment? -->
<exec
command="${progs.mysql} -h${db.host} -u${db.user} -p${db.pass} -e 'USE ${db.main_db}; SELECT MAX(`change_number`) FROM `changelog`;'"
dir="."
checkreturn="false"
passthru="false"
outputProperty="latest_version_output"
/>
<php expression="preg_replace('/[^0-9]|\r|\n/si', '', '${latest_version_output}');" returnProperty="latest_version_applied" />
<echo msg="Latest delta applied was: ${latest_version_applied}" />
The PDOSQLExecTask comes with two default formatters, which will send their output to a file. To change this, you'd probably have to implement your own formatter. On the other hand, the task appears to read its SQL commands from a separate file with SQL commands, not the build file.
So on the whole, It seems to me like you might be better of writing your own task, probably using some code from the implementation of PDOSQLExecTask but with your own command input and result output. Unless calling the mysql command line binary is an alternative for you, in which case you could wrap up that call to redirect its output to a property using the outputProperty attribute to the ExecTask.

Set database name dynamically in LINQ to SQL

I am using LINQ to SQL to connect to database from my application. When I am changing environment from production to staging, I can update my connection string in web.config.
But there is one more value I need to update when environment changes. That is database name. In LINQ to SQL designer file, database name is mentioned as attribute like-
[System.Data.Linq.Mapping.DatabaseAttribute(Name="somedbname")]
How can I pick up value of Name dynamically from some config file?
Any help is really appreciated.
as mentioned on the
http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.databaseattribute.name.aspx
"The DatabaseName is used only if the connection itself does not specify the database name."
so you can delete this attribute and all is gonna work fine!
I've used a wrapper class to provide a context along the lines of
public DataContext Context = new DataContext(SqlConnectionString); //much simplified
I fixed this problem by editing the .dbml file outside of Visual Studio (the designer doesn't seem to allow access to the DatabaseAttribute) and getting rid of the name property here:
<Database Name="BadName" Class="OutputDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
(note that the accepted answer is no longer correct: this attribute was overriding my connection string)