everyone.I try to rewrite the source code of the mybatis generator.but i met a problem that the generator can't get the comment of a database column,and i can't find the problem(i think the source code is right,and don't know what's wrong).here is the source code:
ResultSet rs = databaseMetaData.getColumns(localCatalog, localSchema, localTableName, null);
introspectedColumn.setRemarks(rs.getString("REMARKS"));
introspectedColumn is the generator's class for the database column.
does anybody know about it?Thank you very much!!!
Related
So I am debugging our application which uses Entity Framework Core 2.1.14. I created my entities from database first by scaffolding. Database is MySQL 5.7.29, the SQL data provider for EF Core is Oracle's MySql.Data.EntityFrameworkCore 8.0.19.
Example: a simple Linq query should create a proper SQL statement in the backend. However it does not. "Inactive" is a Byte?.
Dim associates = (From a In DatabaseContext.Associate
Where a.Inactive = 0
Select a.AssociateId).ToList()
This simple Linq query returns: SELECT `a`.`Inactive`, `a`.`AssociateID` FROM `associate` AS `a`. So basically it downloads all associates and does the "where" in memory and returns the values. I know according to the documentation some queries can be complicated and can't be translated, but this is a simplest of the simple queries. Is it because the Inactive column is nullable? Something is terrible not right.
FYI: EF Core is in a class library that is C#. The VB code is in another project that is VB that references the class library.
Hmm, seems the answer is to make the query more specific in VB. I guess the query conversion between C# class library and VB project seems to be the issue.
Dim associates = (From a In DatabaseContext.Associate
Where a.Inactive.Value = Convert.ToByte(0)
Select a.AssociateId).ToList()
This provides the correct query:
SELECT `a`.`AssociateID`
FROM `associate` AS `a`
WHERE `a`.`Inactive` = 0
Very weird that in C# you don't have to check against the .Value and convert the 0 to a byte but in VB I had to do it, there was no other way to get it work. Thanks for everyone trying to help with this.
is there any query to return information about the current script that is running it ?
like for example if i have a file in
/home/domain/public_html/script.php
i want to put a query in it that file to return the filename and path i.e :
/home/domain/public_html/script.php
or at least the base path to it ]
/home/domain/public_html/
pleas note i know lots of method to do this but i specifically want to get these information back from database in response and after running a query
No, there is no way for the MySQL Server to know the name or path to the PHP script that is executing queries unless you tell it.
I've seen some projects that establish a coding practice to append a comment to the SQL queries with information to help you identify the source.
SELECT * FROM MyTable WHERE id = 123; /* File: script.php, Function: myFunction() */
You then see these comments appearing in the MySQL processlist, and in query logs.
You have to write code to put the comment into the SQL yourself:
$sql = sprintf("SELECT * FROM MyTable WHERE id = 123; /* File: %s, Function: %s() */",
__FILE__, __FUNCTION__);
If you don't want to change the code, another great solution is to use New Relic Application Monitoring, which tracks SQL queries in code for you, without any need to modify your code. It's costly to pay for the New Relic service, but it's the best solution. If you want to explore cheaper alternatives, search google "alternatives to new relic".
I'm working with EntityFramework 5.0 and MySql. I have generated model from database, and my application now have to connect on multiple database with same structred data.
So i have to dynamic change connection string based on some info.
I try to change database name even from config section of connection string, and with EntityConnectionStringBuilder, but i had the same result: my new connection is stored correctly, but data returned are of the first database.
From WebConfig:
add name="dbIncassiEntities" connectionString="metadata=res:///DAL.Modelincassi.csdl|res:///DAL.Modelincassi.ssdl|res://*/DAL.Modelincassi.msl;provider=Devart.Data.MySql;provider connection string="user id=root ... database=dbname2"" providerName="System.Data.EntityClient" />
From code:
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = providerName;
entityBuilder.ProviderConnectionString = "user id=...database=dbname2";
entityBuilder.Metadata = #"res://*/DAL.Modelincassi.csdl|res://*/DAL.Modelincassi.ssdl|res://*/DAL.Modelincassi.msl";
var context = new dbIncassiEntities(entityBuilder.ToString());
My constructor:
public dbIncassiEntities(string conn)
: base(conn)
{
}
What am i missing?
UPDATE
I can see that calling a query directly from SqlQuery, results returned are correct,
while using the generated entities i retrieve wrong data.
var test = context.Database.SqlQuery<string>(
"SELECT cognomenome FROM addetto limit 0,1").ToList();
But calling..
var oAddetto = from c in context.addettoes select c;
So my problem is only on the model itsself, and manually changing the generated schema
<EntitySet Name="addetto" EntityType="dbIncassiModel.Store.addetto" store:Type="Tables" Schema="dbname2" />
..i'll get the right information.
My question now is: how can i change in code these informations??
Any help is really appreciated!!
Thanks, David
Ok, i've found a workaround for now.
I simply clear the shema name on the designer, and now i can call the generated entities succesfully. Hope this can help anyone else.
David
While I could not remove the Schema in the designer, I removed it directly in the .edmx file. Do a full text search for Schema="YourSchema" in an XML editor of your choice and remove the entries. After that, changing the connection string is enough.
Downside is, the Visual Studio designer and mapping explorer won't work properly anymore.
This seems to be more of a dotConnect issue rather than MySQL, since the problem also exists for the Oracle adapter:
http://forums.devart.com/viewtopic.php?t=17427
My application dynamically creates tables, and I don't know how to read a table using Spring jdbc without hard coding it into the string query. I was thinking about something like this:
jdbcTemplate.query("SELECT * FROM ?", new Object[] { tableName }, new TableMapper());
But spring doesn't like the question mark :-(
Thanks for any help!
Try String query = String.format("SELECT * FROM %s", tableName);
A word of explanation: Spring is not the one to blame here, the exception is thrown all the way from your DB driver. PreparedStatement doesn't allow parametrising the table name, you can apply the ? to query parameters only. As noted in the other answer, the only way to go around this is to insert it into the query string.
I keep receiving the error
"LINQ to Entities does not recognize the method 'System.String get_Item(Int32)' method, and this method cannot be translated into a store expression"
on the following line in my code
var Reviewer = repository.reviewers.FirstOrDefault(t => t.ReviewerName == formCollection[3]);
formCollection[3] is a string returned from a drop down I have contained within a form. The query seems to work O.K. until it returns the value from the database. What can I do to fix this?
OK, I was trying to do too much at once, when I finally thought about it and put formCollection[3] into a string variable and then used the string variable in the linq query everything worked out ok.