Sometimes you want to mark a DB table record as deleted instead of deleting it permanently, right?
How do you do that?
So far I've been using a boolean "deleted" field.
Basically i want to keep the transaction very simple but i should be able to rollback if any error in the later part.
Something like mentioned below,
BEGIN TRANSACTION
DELETE SET 1(this will delete first set of table)
COMMIT
DELETE SET 2 (will delete second set of table)
If any error occurs while deleting set 2 i should be able to rollback set 1 transaction as well.Let me know if we have any options to do like this. Appreciate for your help.
How can i create a 3 table schema from the following model classes.
public class Product
{
public int Id {get; set;}
public string Name {get; set;}
public IList<Photo> Photos {get; set;}
}
public class Photo
{
public int Id {get; set;}
public string Path {get; set;}
}
I want to create the following table structure in the database:
Product
-------
Id
Name
ProductPhotos
-------------
ProductId (FK Products.Id)
PhotoId (FK Photos.Id)
Photos
------
Id
Path
How i can express the above Database Schema using Fluent NHibernate? I could only manage the following the Mapping but this does not get me the 3rd Photo ref table.
public class ProductMap : ClassMap<Product>
{
public CityMap()
{
Id(x => x.Id);
Map(x => x.Name);
Table("Products");
HasMany(x => x.Photos).Table("ProductPhotos").KeyColumn("ProductId");
}
}
If one has a number of databases (due to separate application front-ends) that provide a complete picture - for example a CRM, accounting, and product database - what methods are available to centralize/abstract this data for easy reporting?
Essentially, I'm wondering if there is a way to automatically pull data from multiple databases into a central repository that is continuously updated from the three databases and which can be used for reporting?
I'm also open to alternative best practice suggestions?
Hello, I have a table with OWN_ID and OWN_Email -
3ace7cf80edd | [email protected]
3acf6af33ff7 | [email protected]
3acda2524e00 | [email protected]
3ad75583c9a7 | [email protected]
3ad74b018999 | [email protected]
etc.
the problem is that it should contain only a single ID per Email, also I need to replace all OWN_ID values in another table by highest OWN_ID value of the OWN_Email
I am currently trying to display the username of people who i am following, the problem is that during the following process, only the ID of me and the person i'm following is stored.
I've got it to the point where the ID's are displayed but i'd like to show the names hyperlinked. $p_id is the profile ID.
Here's what I've got:
$following = mysql_query("SELECT `follower`, `followed` FROM user_follow WHERE follower=$p_id");
I am following: <?php while($apple = mysql_fetch_array($following)){
echo '<a href="'.$apple['followed'].'">+'.$apple['followed'].'</a> ';
}?>
The usernames are in a different table "users" under the field "username" - I need them to match up with the ID's that are currently displayed, and be displayed.
Any help appreciated,
thanks guys
I have SQL Server 2008. I run a query in a table on a database. The weirdest thing keeps happening. I run a simple select statement on the table. I know there are 62 rows in the table but it gets stuck at row 48 and goes on "querying...". Waited already for hours and it didn't move on from there. I only know of two programs, and one reporting service connecting to that particular table and one other user. Does anyone have any idea on what could be causing this and how I could trace the source of the lock on that table?
As a side note, I noted that the logs only had a notice that Autogrow failed the day before I checked. Could this have something to do with it?
Hi,
when running a Java application as service with the user 'LocalService', the temp directory ("java.io.tmpdir") points to 'c:/windows/temp' (for example).
Running a Java application normally gives 'c:/documents and settings/user/local settings/temp' instead.
How can I determine the user independent temp folder 'c:/windows/temp' when my application runs normally?
Thanks and greetings,
GHad
It's been asked a million times, its like this.
Say Invoice is the base class and InvoiceHistory is the class that simply inherits from Invoice.
When I do something like
invoiceList = session.CreateCriteria(typeof(Invoice)).List();
I get everything from Invoice (that I want, plus everything from InvoiceHistory).
Do I need to have an InvoiceBase and create derived versions for Invoice and InvoiceHistory?
how do i write a query that returns aggregate sales data for California in the past x months.
----------------------- -----------------------
| order | | customer |
|-----------------------| |-----------------------|
| orderId int | | customerId int |
| customerId int | | state varchar |
| deposit decimal | -----------------------
| orderDate date |
-----------------------
-----------------------
| orderItem |
|-----------------------|
| orderId int |
| itemId int |
| qty int |
| lineTotal decimal |
| itemPrice decimal |
-----------------------
I wonder if this is possible with straight SQL on MySQL. I need to do SELECT COUNT(*) FROM on each table in the database and output results in one result set.
Is it possible to do with just SQL?
I have 6 classes and I try to use linq to Entities to get the SiglaUF information of the last deeper table (in the view - MVC). The problem is I receive the following error:
"The ObjectContext instance has been disposed and can no longer be used for operations that require a connection."
The view is like that:
> @model IEnumerable<DiskPizzaDelivery.Models.EnderecoCliente>
> @foreach (var item in Model) {
> @Html.DisplayFor(modelItem => item.CEP.Cidade.UF.SiglaUF)
> }
The query that i use:
var cliente = context.Clientes
.Include(e => e.Enderecos)
.Include(e1 => e1.Enderecos.Select(cep => cep.CEP))
.SingleOrDefault();
The question is: How Can I improve this query to pre loading (eager loading) "Cidade" and "UF"?
See below the classes:
public partial class Cliente
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int IdCliente { get; set; }
public string Email { get; set; }
public string Senha { get; set; }
public virtual ICollection<EnderecoCliente> Enderecos { get; set; }
}
public partial class EnderecoCliente
{
public int IdEndereco { get; set; }
public int IdCliente { get; set; }
public string CEPEndereco { get; set; }
public string Numero { get; set; }
public string Complemento { get; set; }
public string PontoReferencia { get; set; }
public virtual Cliente Cliente { get; set; }
public virtual CEP CEP { get; set; }
}
public partial class CEP
{
public string CodCep { get; set; }
public string Tipo_Logradouro { get; set; }
public string Logradouro { get; set; }
public string Bairro { get; set; }
public int CodigoUF { get; set; }
public int CodigoCidade { get; set; }
public virtual Cidade Cidade { get; set; }
}
public partial class Cidade
{
public int CodigoCidade { get; set; }
public string NomeCidade { get; set; }
public int CodigoUF { get; set; }
public virtual ICollection<CEP> CEPs { get; set; }
public virtual UF UF { get; set; }
public virtual ICollection<UF> UFs { get; set; }
}
public partial class UF
{
public int CodigoUF { get; set; }
public string SiglaUF { get; set; }
public string NomeUF { get; set; }
public int CodigoCidadeCapital { get; set; }
public virtual ICollection<Cidade> Cidades { get; set; }
public virtual Cidade Cidade { get; set; }
}
var cliente = context.Clientes
.Where(c => c.Email == email)
.Where(c => c.Senha == senha)
.Include(e => e.Enderecos)
.Include(e1 => e1.Enderecos.Select(cep => cep.CEP))
.SingleOrDefault();
Thanks!
So I can do Post.delete_all to delete all my posts, but what if I want to delete all posts, comments, blogs, etc. I.e., how do I iterate over all my models and run the delete_all method?
I'd like to run a query like this:
$rsm = new ResultSetMappingBuilder($this->em);
$rsm->addRootEntityFromClassMetadata('myBundle:Foo', 'f');
$rsm->addRootEntityFromClassMetadata('myBundle:Bar', 'b');
$sql = 'SELECT l.*, b.* FROM foos f
INNER JOIN FROM bars b
ON b.baz_id = f.baz_id
WHERE l.bam = 1';
$query = $this->em->createNativeQuery($sql, $rsm);
$fooBarQuery= $query->getResult();
Unfortunately this is not a situation where I can set up a proper relationship in the entity. Is not going to be possible for me to do this? Thanks.
Consider the task of replacing this table with CSS stylings:
<table border="1">
<tr><td align="center">
<img src="foo" />
</td></tr>
<tr><td align="center">
<img src="bar" />
</td></tr>
<tr><td align="center">
<img src="bat" />
</td></tr>
</table>
The desired output is 3 images stacked on top of each other. The images are centered on the widest of them all.
How would you style this markup with <div> around those <img> tags with CSS to achieve the same look?
Hi all,
My situation is next: there are to entities with many-to-many relation, f.e. Products and Categories. Also, categories has hierachial structure, like a tree. There is need to select all products that depends to some concrete category with all its childs (branch). So, I use following sql statement to do that:
SELECT * FROM Products p
WHERE p.ID IN (
SELECT DISTINCT pc.ProductID FROM ProductsCategories pc
INNER JOIN Categories c ON c.ID = pc.CategoryID
WHERE c.TLeft >= 1 AND c.TRight <= 33378
)
But with big set of data this query executes very long and I found some solution to optimize it, look at here:
DECLARE @CatProducts TABLE (
ProductID int NOT NULL
)
INSERT INTO @CatProducts
SELECT DISTINCT pc.ProductID FROM ProductsCategories pc
INNER JOIN Categories c ON c.ID = pc.CategoryID
WHERE c.TLeft >= 1 AND c.TRight <= 33378
SELECT * FROM Products p
INNER JOIN @CatProducts cp ON cp.ProductID = p.ID
This query executes very fast but I don't know how to do that with NHIbernate. Note, that I need use only ICriteria because of dynamic filtering\ordering.
If some one knows a solution for that, it will be fantastic. But I'll pleasure to any suggestions of course.
Thank you ahead,
Kostya
The Django documentation gives en example like so:
b = Blog.objects.get(id=1)
b.entry_set.all()
Which from what I understand results in 2 queries. What if I wanted to get the blog, the blog entries and all the comments associated with that entry in a number of queries that does not depend on the number of entries? Or do I have to drop down to SQL to do that?
I'm trying to write up a script where the user is able to purchase an amount of points for dollars. I want the transaction to be inserted into MySQL. I keep facing a: "Column count doesn't match value count at row 1" error. And I have no idea what I'm doing wrong.
I have written up this:
mysql_query("INSERT INTO paypal_donations VALUES (NULL, ".$account_id.", ".$char_id.", ".$price.", ".$dp.", NOW(), NOW(), 'Started', 0, 0, '', '');") or die(mysql_error());
But I don't know what to execute in MySQL, since I've never worked with it before.
Could anyone write up a quick script that I can insert into MySQL for it to work.
hello !
languages table(languagename,languagecode(pk),part);
parts table(subjectype,part(pk));
I want to access only perticular subject type into drop downs...
How can i do this.
I don-t know how to use one table from one database and second table from another databse at the same time or copy data from table in one database to table from another databse.
I tried following query:
select * into NewTable from existingdb.dbo.existingTable;
But it doesnt't work.
Table 1 has columns : entry_id user_id ...
Table 2 has columns : entry_id user_id ...
the user_id entry is not always the same so I would like to extract both of them so I can later on compare them in my script
SELECT * FROM
table1 as t1
INNER JOIN table2 as t2 on t1.entry_id=t2.entry_id
WHERE t1.user_id='%s'
I would like to extract t1.user_id and t2.user_id ...the problem is the result array has only user_id
thank you
This is the structure of my table:
Then I run a query
SELECT `date`,`index_name`,`results` FROM `mst_ind` WHERE `index_name` IN ('MSCI EAFE Mid NR USD', 'Alerian MLP PR USD') AND `time_period`='M1'
and get a table like
How can I convert "index_name" rows to columns like:
date | MSCI EAFE Mid NR USD | Alerian MLP PR USD etc
In other words I need each column to represent an index and rows to represent date-result. I understand that MySQL doesn't have pivot table functions. What is the easiest way of doing this?
I've tried this code, but it generates an error:
SELECT
`date`,
MAX(IF(index_name = 'Alerian MLP PR USD' AND `time_period`='M1', results, NULL)) AS res1,
MAX(IF(index_name = 'MSCI EAFE Mid NR USD' AND `time_period`='M1', results, NULL)) AS res2
FROM
`mst_ind`
GROUP BY `date
I need to make the conversion on the query level - not PHP. Please suggest a nice and elegant solution. Thanks!
I want to push a 2d vector into a hash table row by row and later search for a row (vector) in the hash table and want to be able to find it. I want to do something like
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
std::set < vector<int> > myset;
vector< vector<int> > v;
int k = 0;
for ( int i = 0; i < 5; i++ ) {
v.push_back ( vector<int>() );
for ( int j = 0; j < 5; j++ )
v[i].push_back ( k++ );
}
for ( int i = 0; i < 5; i++ ) {
std::copy(v[i].begin(),v[i].end(),std::inserter(myset)); // This is not correct but what is the right way ?
// and also here, I want to search for a particular vector if it exists in the table. for ex. the second row of vector v.
}
return 0;
}
I'm not sure how to insert and look up a vector in a set. So if nybody could guide me, it will be helpful. Thanks