SubSonic 3 Using Insert.Into<> without having to specify column names and values? - subsonic

I'm just starting to use SubSonic 3 and I'm struggling with a basic insert operation.
I would like to insert a new row into a table with all columns and values as specified by an entity object. However the only examples I can find look like you have to specify each column and value, which to me isn't a big step up from doing the raw SQL insert!
myDB.Insert.Into<MyTable>(m => m.Col1, m=m.Col2, etc).Values(col1Val, col2Val,...)
I'm not using the ActiveRecord template which I know from 2.x can do this and there doesn't seem to a Repository.tt template with the version I downloaded (SubSonic.Core 3.0.0.3).
So is this possible?
Is there a Repository.tt template available for v3.0.0.3?
Thanks,
Canice.

You will not need a Repository.tt all you need is to instantiate an instance of SimpleRepository and call the Insert method which takes a type as generic argument and instance which is persisted.
You can take a look at the simple repository tests on github:
https://github.com/subsonic/SubSonic-3.0/blob/master/SubSonic.Tests/Repositories/SimpleRepositoryTests.cs

Related

How To Update Field of a User-Defined Type (UDT) with Spring Data Cassandra CassandraTemplate

I have a Cassandra table which includes a user-defined type. Using CassandraTemplate from Spring Data Cassandra, I want to update a single field of that UDT. This doesn't seem possible.
I have tried this:
database.update(query(
where("party_id").is(partyId)).and(where("relationship_id").is(relationshipId)),
update("address.address_line_1", "this field was updated"),
Address.class);
This throws:
Query error after 3 ms: UPDATE current_addresses_by_party SET "address.address_line_1"=? WHERE party_id=? AND relationship_id=?;com.datastax.driver.core.exceptions.InvalidQueryException: Undefined column name "address.address_line_1"
Running the CQL given in the error output without the quotes works. I don't know if there's a way to get Spring to execute this statement without putting the column name in quotes.
In a fit of optimism I also tried using the syntax for map types:
database.update(query(
where("party_id").is(partyId)).and(where("relationship_id").is(relationshipId)),
Update.empty().set("address").atKey("address_line_1").to("this field was updated"),
Address.class)
This resulted in the error you would expect: the field is not a map.
Is there a way to do what I want with CassandraTemplate without resorting to direct CQL? If CassandraTemplate lacks this feature, it would be great if the devs added it.
I was surprised that I couldn't find anyone else wanting to do this. Maybe I'm doing something completely wrong? I'm fairly new to Cassandra.

Getting the result of an excel formula in python

I need to open a .xlsx-file (without writing to it) in python, to change some fields and get the output after the formulas in some fields were calculated; I only know the input fields, the output field and the name of the sheet.
To write some code: Here is how it would look like if I would have created the library
file = excel.open("some_file.xlsx")
sheet = file[sheet_name]
for k, v in input_fields.items():
sheet[k] = v
file.do_calculations()
print(sheet[output_field])
Is there an easy way to do this? Wich library should I use to get the result of the formulas after providing new values for some fields?
Is there a better way than using something like pyoo, maybe something that doesn't require another application (a python library is clearly better) to be installed?
I'll just thank you in advance.
I now came up with a (very ugly) solution.
I am now reading the xml within the xlsx-file, and I am now using eval and some regular expressions to find out wich fields are needed; and I have defined some functions to run the calculations.
It works, but it would be great if there were a better solution.
If the resulting library is ready, and I don't forget to do this; I'll add a link to the library (that'll be hosted on Github) to this answer to my own question.

SSIS: Filtering Multiple GUIDs from String Variable as Parameter In Data Flow OLE Source

I have an SSIS package that obtains a list of new GUIDs from a SQL table. I then shred the GUIDs into a string variable so that I have them separated out by comma. An example of how they appear in the variable is:
'5f661168-aed2-4659-86ba-fd864ca341bc','f5ba6d28-7283-4bed-9f11-e8f6bef225c5'
The problem is in the data flow task. I use the variable as a parameter in a SQL query to get my source data and I cannot get my results. When the WHERE clause looks like:
WHERE [GUID] IN (?)
I get an invalid character error so I found out the implicit conversion doesn't work with the GUIDs like I thought they would. I could resolve this by putting {} around the GUID if this were a single GUID but there are a potential 4 or 5 different GUIDs this will need to retrieve at runtime.
Figuring I could get around it with this:
WHERE CAST([GUID] AS VARCHAR(50)) IN (?)
But this simply produces no results and there should be two in my current test.
I figure there must be a way to accomplish this... What am I missing?
You can't, at least not using the mechanics you have provided.
You cannot concatenate values and make that work with a parameter.
I'm open to being proven wrong on this point but I'll be damned if I can make it work.
How can I make it work?
The trick is to just go old school and make your query via string building/concatenation.
In my package, I defined two variables, filter and query. filter will be the concatenation you are already performing.
query will be an expression (right click, properties: set EvaluateAsExpression to True, Expression would be something like "SELECT * FROM dbo.RefData R WHERE R.refkey IN (" + #[User::filter] + ")"
In your data flow, then change your source to SQL Command from variable. No mapping required there.
Basic look and feel would be like
OLE Source query

Table and Column names causing problems

I have an issue when the T4 linq templates generate the classes for my MySql db using subsonic 3.
It looks like one of our table names "operator" is causing problems in the Context.cs generated class. In the following line of code in Context.cs Visual Studio sees <operator> as a c# operator and generates a compilation error of "Type expected"
public Query<operator> operators { get; set; }
Is there anyway I can work around this without having to rename my database table and column names? For example hard coding something in Settings.ttinclude to use or map different names to specific db tables and columns?
The CleanUp() function was built for this - it's in Settings.tt. You should be able to rename your class as needed.

Invalid Parameter Name

I am having a problem with saving of data because of an incorrectly generated parameter name.
The table has a field "E-mail", and when the class wrapper is generated, the InsertCmd uses "#E-mail" as one of the parameters. In SQL Server, this is illegal and generated an exception.
I have hunted all over SubSonic for a way to modify the parameter name to simply "#Email" but the ParameterName property is read only.
I am using SubSonic 2.2 and don't have the source for it to make an internal modification.
Any ideas?
TIA
I got a mate of mine that uses SVN to pull the source code, and as expected, found a bug in the SS source.
When the column name is set in the class wrapper, the setter for the ColumnName property sets the ParamaterName property for you correctly using
"parameterName = Utility.PrefixParameter(Utility.StripNonAlphaNumeric(columnName), Table.Provider);". This removes any illegal characters like the hyphen in my E-mail column.
BUT... The property ParameterName is NOT used when the SQL commands are created. Here is the code in SQLDataProvider.GetInsertSQL, line 1462.
pars.Append(Utility.PrefixParameter( colName, this));
I changed this to
pars.Append(col.ParameterName);
and the problem is now sorted.
Thanks to you that came up with possible solutions.
You can modify the templates if you can't change the column name. See this blog post for details of how:
http://johnnycoder.com/blog/2008/06/09/custom-templates-with-subsonic/

Resources