Removing array element does not work
there is a $_SESSION array that holds the ID of user's currently selected
products (which are in the cart). Now, when the user sees his bill, he
want to remove an item (product) from his cart, I have put him a link to
do so. but the script does not work. I have configured a $_GET['itemid']
in the URL and by using it, I unset() that array element.
BUT it does not work. What should I do? Here is my code
function remove_from_cart($stack_id) // stack_id is the id of the item in
cart array ($_SESSION)
{
for($i=0; $i < count($_SESSION['add-to-cart-item']); $i++)
{
if($_SESSION['add-to-cart-item'][$i] == $stack_id)
{
unset($_SESSION['add-to-cart-item'][$stack_id]);
}
}
}
Busse
Sunday, 1 September 2013
Saturday, 31 August 2013
Why is my SQL "INSERT INTO" Query not working?
Why is my SQL "INSERT INTO" Query not working?
I'm making a storage log for work, and I've been fighting with this code
for the last two hours with no success. For some reason, no matter how
many times I check and recheck the code for my INSERT INTO query, it will
not work. Keep in mind that I copied this code, almost verbatim (changed
the form names, and fields, obviously) from another page that has
basically the same functionality and works 100%. Code below:
This is the page containing the form where the transaction is being
submitted:
<?php
$script = '<script>
$(document).ready(function(){
$(".datepicker").datepicker();
}); </script>' ;
$title = "View/Edit Storage - " ;
include('inc/header.php');
?>
<table>
<tr>
<form action="transadded.php" name='addnewtransaction'
method="POST">
<td><input type="text" name="moveID" size="20"
value="<?php echo $results[moveid]; ?>" readonly>
</td>
<td><select id="inoutselect" name="inorout">
<option value="Select">Select</option>
<option value="Storage In">Storage In</option>
<option value="Storage Out">Storage Out</option>
</select> </td>
<td><input type="text" name="numberofunits"
size="20"></td>
<td><input type="text" name="dateoftransaction"
size="20" class="datepicker"></td>
<td><input type="text" name="rrdt" size="20"> </td>
<td><input type="submit" value="Add" id="logsubmit"></td>
</form>
</table>
<br /><br />
<?php };?>
Here's the query itself, aka "transadded.php":
<?php
$title = "Project Added - ";
include('inc/header.php');
$query = "INSERT INTO newtransaction (moveid, inout, units, transdate,
refno)
VALUES('$_POST[moveID]','$_POST[inorout]','$_POST[numberofunits]','$_POST[dateoftransaction]','$_POST[rrdt]')";
if(!mysqli_query($con,$query))
{
die ('Error: ' . mysqli_error($con));
}
echo '<div class="transstatus">' . '1 record added' . '</div>';
mysqli_close($con);
?>
The header, obviously, contains the function for connecting to the
database, and as I said, another query works just fine with it, so I know
that that isn't the problem. Upon clicking the submit button, the error I
get on the page is as follows:
Error: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'inout, units, transdate, refno) VALUES ('1234567','Storage
In','81','09/11/2013'' at line 1
Here, "1234567", "Storage In", etc are the values I enter into the form.
I hope you guys can help me out. I'm so stuck!
Also, I know that I'm not protected against injection right now. I plan to
work on that later, but I'm trying to get the functionality straightened
out first.
Thanks!
I'm making a storage log for work, and I've been fighting with this code
for the last two hours with no success. For some reason, no matter how
many times I check and recheck the code for my INSERT INTO query, it will
not work. Keep in mind that I copied this code, almost verbatim (changed
the form names, and fields, obviously) from another page that has
basically the same functionality and works 100%. Code below:
This is the page containing the form where the transaction is being
submitted:
<?php
$script = '<script>
$(document).ready(function(){
$(".datepicker").datepicker();
}); </script>' ;
$title = "View/Edit Storage - " ;
include('inc/header.php');
?>
<table>
<tr>
<form action="transadded.php" name='addnewtransaction'
method="POST">
<td><input type="text" name="moveID" size="20"
value="<?php echo $results[moveid]; ?>" readonly>
</td>
<td><select id="inoutselect" name="inorout">
<option value="Select">Select</option>
<option value="Storage In">Storage In</option>
<option value="Storage Out">Storage Out</option>
</select> </td>
<td><input type="text" name="numberofunits"
size="20"></td>
<td><input type="text" name="dateoftransaction"
size="20" class="datepicker"></td>
<td><input type="text" name="rrdt" size="20"> </td>
<td><input type="submit" value="Add" id="logsubmit"></td>
</form>
</table>
<br /><br />
<?php };?>
Here's the query itself, aka "transadded.php":
<?php
$title = "Project Added - ";
include('inc/header.php');
$query = "INSERT INTO newtransaction (moveid, inout, units, transdate,
refno)
VALUES('$_POST[moveID]','$_POST[inorout]','$_POST[numberofunits]','$_POST[dateoftransaction]','$_POST[rrdt]')";
if(!mysqli_query($con,$query))
{
die ('Error: ' . mysqli_error($con));
}
echo '<div class="transstatus">' . '1 record added' . '</div>';
mysqli_close($con);
?>
The header, obviously, contains the function for connecting to the
database, and as I said, another query works just fine with it, so I know
that that isn't the problem. Upon clicking the submit button, the error I
get on the page is as follows:
Error: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'inout, units, transdate, refno) VALUES ('1234567','Storage
In','81','09/11/2013'' at line 1
Here, "1234567", "Storage In", etc are the values I enter into the form.
I hope you guys can help me out. I'm so stuck!
Also, I know that I'm not protected against injection right now. I plan to
work on that later, but I'm trying to get the functionality straightened
out first.
Thanks!
Multiple channel's message comes into single channel
Multiple channel's message comes into single channel
i am fresher of Spring Integration, i am confuing one question which i
have multiple channels but now i want to assemble messages from those
channel into single channel, how to implement it ? my senario is that i
have lots of businees modues and each module will corresponding to one
channel, those channels will receive the request then assemble the message
into one single channel , then output to the jms server:
is below code possible ?
<channel id='a'/> <bridge input-channel='a' out-channel='assembled'/>
<channel id='b'/> <bridge input-channel='b' out-channel='assembled'/>
<channel id='b'/> <bridge input-channel='c' out-channel='assembled'/>
<channel id='c'/> <bridge input-channel='d' out-channel='assembled'/>
<channel id='assembled'/>
<!-- the router will desicde which jms gateway to be sent -->
<router input-channel='assembled' >
<channel id='to_jms1'/>
<channel id='to_jms2'/>
<jms-outbound-gateway id='jms1' channel='to_jms1'/>
<jms-outbound-gateway id='jms2' channel='to_jms2'/>
i am fresher of Spring Integration, i am confuing one question which i
have multiple channels but now i want to assemble messages from those
channel into single channel, how to implement it ? my senario is that i
have lots of businees modues and each module will corresponding to one
channel, those channels will receive the request then assemble the message
into one single channel , then output to the jms server:
is below code possible ?
<channel id='a'/> <bridge input-channel='a' out-channel='assembled'/>
<channel id='b'/> <bridge input-channel='b' out-channel='assembled'/>
<channel id='b'/> <bridge input-channel='c' out-channel='assembled'/>
<channel id='c'/> <bridge input-channel='d' out-channel='assembled'/>
<channel id='assembled'/>
<!-- the router will desicde which jms gateway to be sent -->
<router input-channel='assembled' >
<channel id='to_jms1'/>
<channel id='to_jms2'/>
<jms-outbound-gateway id='jms1' channel='to_jms1'/>
<jms-outbound-gateway id='jms2' channel='to_jms2'/>
Hibernate maps with discrimination column or class name as key
Hibernate maps with discrimination column or class name as key
I've been pulling my hair out over this for the best part of a day now,
and simply can't find any answers to this problem.
I've got a PostgreSQL schems that looks like this:
+---------+ 1-n +-------------+ 1-1 +------+
| Product |-------->| ProductSpec |-------->| Spec |
+---------+ +-------------+ +------+
This represents a one to many relationship between a Product and its list
of Specifications (The reason I don't just use a foreign key in the
specifications table into the products table is because specifications can
belong to things that aren't in the product inheritance tree, those links
are represented by other intersection tables).
Each Specification is a subclass of a Specification class (Weight, Length,
NumberOfThings, and so on), with the name of the subclass in question
being stored in the Spec table. Each product has a collection of
specifications, but each subclass of specification can only appear once. A
product can only have one weight (though if you need a weight for the
actual product, and a shipping weight for the courier to calculate
shipping charges, you can simply subclass ActualWeight and ShippingWeight
from the Weight specification).
Using the simplest case, a Set in the Product class, I'm able to construct
the object graph correctly from a Hibernate query of the products table. I
want to use a Map instead, however, so I can address specific
specifications directly. The plan was to use the class name as the key,
but I'm having serious issues trying to get it to work. I'm unable to
figure out how to use the Java class name as the key, and trying to use
the class name as stored in the database as the map key is proving
problematic.
As currently implemented, I'm able to query the specifications, and the
products individually (if I comment out the code implementing the mapping
between products and specifications). I can also query the products with
the specifications embedded if I use a set, but if I use a map with the
MapKey set to be the specifications class name, I get an exception.
Sep 01, 2013 1:25:55 AM org.hibernate.util.JDBCExceptionReporter
logExceptions WARNING: SQL Error: 0, SQLState: 42P01 Sep 01, 2013 1:25:55
AM org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: ERROR:
relation "specifications" does not exist Position: 424
I've annotated my (cut down) classes as follows. The product class:
@Entity
@Table (
name="products",
schema="sellable"
)
public abstract class Product extends Sellable {
private Map <String, Specification> specifications = new HashMap <> ();
@OneToMany (fetch = FetchType.EAGER)
@Cascade (CascadeType.SAVE_UPDATE)
@JoinTable (
schema = "sellable",
name = "productspecifications",
joinColumns = {@JoinColumn (name = "sll_id")},
inverseJoinColumns = {@JoinColumn (name = "spc_id")})
@MapKey (name = "className")
private Map <String, Specification> getSpecifications () {
return this.specifications;
}
private Product setSpecifications (Map <String, Specification> specs) {
this.specifications = specs;
return this;
}
}
And the Specification class:
@Entity
@Table (
name="specifications",
schema="sellable",
uniqueConstraints = @UniqueConstraint (columnNames="spc_id")
)
@Inheritance (strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn (name = "spc_classname",
discriminatorType=DiscriminatorType.STRING)
public abstract class Specification implements Serializable {
private Integer specId = null;
private String className = null;
@Id
@Column (name="spc_id", unique=true, nullable=false)
@SequenceGenerator (name = "specifications_spc_id_seq", sequenceName =
"sellable.specifications_spc_id_seq", allocationSize = 1)
@GeneratedValue (strategy = GenerationType.SEQUENCE, generator =
"specifications_spc_id_seq")
public Integer getSpecId () {
return this.specId;
}
private Specification setSpecId (Integer specId) {
this.specId = specId;
return this;
}
@Column (name="spc_classname", insertable = false, updatable = false,
nullable = false)
public String getClassName () {
return this.className;
}
private void setClassName (String className) {
this.className = className;
}
}
The DB schema looks like this:
CREATE TABLE sellable.sellables
(
sll_id serial NOT NULL, -- Sellable ID
sll_date_created timestamp with time zone NOT NULL DEFAULT now(), --
Date the item was created
sll_date_updated timestamp with time zone NOT NULL DEFAULT now(), --
Date the item was last updated
sll_title character varying(255) NOT NULL, -- Title of the item
sll_desc text NOT NULL, -- Textual description of the item
CONSTRAINT sellables_pkey PRIMARY KEY (sll_id)
)
CREATE TABLE sellable.products
(
sll_id integer NOT NULL, -- Sellable ID
mfr_id integer NOT NULL, -- ID of the product manufacturer
CONSTRAINT products_pkey PRIMARY KEY (sll_id),
CONSTRAINT products_mfr_id_fkey FOREIGN KEY (mfr_id)
REFERENCES sellable.manufacturers (mfr_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT products_sll_id_fkey FOREIGN KEY (sll_id)
REFERENCES sellable.sellables (sll_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
CREATE TABLE sellable.specifications
(
spc_id serial NOT NULL, -- Specification ID
spc_classname character varying(127) NOT NULL, -- Specification subclass
CONSTRAINT specifications_pkey PRIMARY KEY (spc_id)
)
CREATE TABLE sellable.productspecifications
(
ps_id serial NOT NULL, -- Primary key
sll_id integer NOT NULL, -- Product the specification is linked to
spc_id integer NOT NULL, -- Specification the product is associated with
CONSTRAINT productspecifications_pkey PRIMARY KEY (ps_id),
CONSTRAINT productspecifications_sll_id_fkey FOREIGN KEY (sll_id)
REFERENCES sellable.products (sll_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT productspecifications_spc_id_fkey FOREIGN KEY (spc_id)
REFERENCES sellable.specifications (spc_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT productspecifications_spc_id_key UNIQUE (spc_id)
)
The query that Hibernate generates is listed below (I've not trimmed this
the way I have the classes in case there's something in the unabridged
query that is an issue). One obvious problem is that it's trying to query
the specifications table without inserting the schema name.
select
bicycle0_.sll_id as sll1_0_3_,
bicycle0_2_.sll_date_created as sll2_0_3_,
bicycle0_2_.sll_date_updated as sll3_0_3_,
bicycle0_2_.sll_desc as sll4_0_3_,
bicycle0_2_.sll_title as sll5_0_3_,
bicycle0_1_.mfr_id as mfr2_1_3_,
bicycle0_.btp_id as btp2_2_3_,
manufactur1_.mfr_id as mfr1_4_0_,
manufactur1_.mfr_name as mfr2_4_0_,
specificat2_.sll_id as sll1_5_,
specificat3_.spc_id as spc2_5_,
(select
a9.spc_classname
from
specifications a9
where
a9.spc_id=specificat2_.spc_id) as formula0_5_,
specificat3_.spc_id as spc2_5_1_,
specificat3_.spc_classname as spc1_5_1_,
specificat3_1_.dec_value as dec1_6_1_,
specificat3_2_.bol_value as bol1_7_1_,
specificat3_3_.int_value as int1_8_1_,
specificat3_4_.str_value as str1_9_1_,
bicycletyp4_.btp_id as btp1_3_2_,
bicycletyp4_.btp_name as btp2_3_2_
from
sellable.bicycles bicycle0_
inner join
sellable.products bicycle0_1_
on bicycle0_.sll_id=bicycle0_1_.sll_id
inner join
sellable.sellables bicycle0_2_
on bicycle0_.sll_id=bicycle0_2_.sll_id
left outer join
sellable.manufacturers manufactur1_
on bicycle0_1_.mfr_id=manufactur1_.mfr_id
left outer join
sellable.productspecifications specificat2_
on bicycle0_.sll_id=specificat2_.sll_id
left outer join
sellable.specifications specificat3_
on specificat2_.spc_id=specificat3_.spc_id
left outer join
sellable.specdecimalvalues specificat3_1_
on specificat3_.spc_id=specificat3_1_.spc_id
left outer join
sellable.specbooleanvalues specificat3_2_
on specificat3_.spc_id=specificat3_2_.spc_id
left outer join
sellable.specintegervalues specificat3_3_
on specificat3_.spc_id=specificat3_3_.spc_id
left outer join
sellable.specstringvalues specificat3_4_
on specificat3_.spc_id=specificat3_4_.spc_id
left outer join
sellable.bicycletypes bicycletyp4_
on bicycle0_.btp_id=bicycletyp4_.btp_id
where
bicycle0_.sll_id=?
The problem is in the sub-query, which isn't getting a schema prepended to
the specifications table name.
If anyone knows how to either get the query to be correct, or of using the
class name directly as the Java map key, I'd appreciate being told.
I've been pulling my hair out over this for the best part of a day now,
and simply can't find any answers to this problem.
I've got a PostgreSQL schems that looks like this:
+---------+ 1-n +-------------+ 1-1 +------+
| Product |-------->| ProductSpec |-------->| Spec |
+---------+ +-------------+ +------+
This represents a one to many relationship between a Product and its list
of Specifications (The reason I don't just use a foreign key in the
specifications table into the products table is because specifications can
belong to things that aren't in the product inheritance tree, those links
are represented by other intersection tables).
Each Specification is a subclass of a Specification class (Weight, Length,
NumberOfThings, and so on), with the name of the subclass in question
being stored in the Spec table. Each product has a collection of
specifications, but each subclass of specification can only appear once. A
product can only have one weight (though if you need a weight for the
actual product, and a shipping weight for the courier to calculate
shipping charges, you can simply subclass ActualWeight and ShippingWeight
from the Weight specification).
Using the simplest case, a Set in the Product class, I'm able to construct
the object graph correctly from a Hibernate query of the products table. I
want to use a Map instead, however, so I can address specific
specifications directly. The plan was to use the class name as the key,
but I'm having serious issues trying to get it to work. I'm unable to
figure out how to use the Java class name as the key, and trying to use
the class name as stored in the database as the map key is proving
problematic.
As currently implemented, I'm able to query the specifications, and the
products individually (if I comment out the code implementing the mapping
between products and specifications). I can also query the products with
the specifications embedded if I use a set, but if I use a map with the
MapKey set to be the specifications class name, I get an exception.
Sep 01, 2013 1:25:55 AM org.hibernate.util.JDBCExceptionReporter
logExceptions WARNING: SQL Error: 0, SQLState: 42P01 Sep 01, 2013 1:25:55
AM org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: ERROR:
relation "specifications" does not exist Position: 424
I've annotated my (cut down) classes as follows. The product class:
@Entity
@Table (
name="products",
schema="sellable"
)
public abstract class Product extends Sellable {
private Map <String, Specification> specifications = new HashMap <> ();
@OneToMany (fetch = FetchType.EAGER)
@Cascade (CascadeType.SAVE_UPDATE)
@JoinTable (
schema = "sellable",
name = "productspecifications",
joinColumns = {@JoinColumn (name = "sll_id")},
inverseJoinColumns = {@JoinColumn (name = "spc_id")})
@MapKey (name = "className")
private Map <String, Specification> getSpecifications () {
return this.specifications;
}
private Product setSpecifications (Map <String, Specification> specs) {
this.specifications = specs;
return this;
}
}
And the Specification class:
@Entity
@Table (
name="specifications",
schema="sellable",
uniqueConstraints = @UniqueConstraint (columnNames="spc_id")
)
@Inheritance (strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn (name = "spc_classname",
discriminatorType=DiscriminatorType.STRING)
public abstract class Specification implements Serializable {
private Integer specId = null;
private String className = null;
@Id
@Column (name="spc_id", unique=true, nullable=false)
@SequenceGenerator (name = "specifications_spc_id_seq", sequenceName =
"sellable.specifications_spc_id_seq", allocationSize = 1)
@GeneratedValue (strategy = GenerationType.SEQUENCE, generator =
"specifications_spc_id_seq")
public Integer getSpecId () {
return this.specId;
}
private Specification setSpecId (Integer specId) {
this.specId = specId;
return this;
}
@Column (name="spc_classname", insertable = false, updatable = false,
nullable = false)
public String getClassName () {
return this.className;
}
private void setClassName (String className) {
this.className = className;
}
}
The DB schema looks like this:
CREATE TABLE sellable.sellables
(
sll_id serial NOT NULL, -- Sellable ID
sll_date_created timestamp with time zone NOT NULL DEFAULT now(), --
Date the item was created
sll_date_updated timestamp with time zone NOT NULL DEFAULT now(), --
Date the item was last updated
sll_title character varying(255) NOT NULL, -- Title of the item
sll_desc text NOT NULL, -- Textual description of the item
CONSTRAINT sellables_pkey PRIMARY KEY (sll_id)
)
CREATE TABLE sellable.products
(
sll_id integer NOT NULL, -- Sellable ID
mfr_id integer NOT NULL, -- ID of the product manufacturer
CONSTRAINT products_pkey PRIMARY KEY (sll_id),
CONSTRAINT products_mfr_id_fkey FOREIGN KEY (mfr_id)
REFERENCES sellable.manufacturers (mfr_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT products_sll_id_fkey FOREIGN KEY (sll_id)
REFERENCES sellable.sellables (sll_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
CREATE TABLE sellable.specifications
(
spc_id serial NOT NULL, -- Specification ID
spc_classname character varying(127) NOT NULL, -- Specification subclass
CONSTRAINT specifications_pkey PRIMARY KEY (spc_id)
)
CREATE TABLE sellable.productspecifications
(
ps_id serial NOT NULL, -- Primary key
sll_id integer NOT NULL, -- Product the specification is linked to
spc_id integer NOT NULL, -- Specification the product is associated with
CONSTRAINT productspecifications_pkey PRIMARY KEY (ps_id),
CONSTRAINT productspecifications_sll_id_fkey FOREIGN KEY (sll_id)
REFERENCES sellable.products (sll_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT productspecifications_spc_id_fkey FOREIGN KEY (spc_id)
REFERENCES sellable.specifications (spc_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT productspecifications_spc_id_key UNIQUE (spc_id)
)
The query that Hibernate generates is listed below (I've not trimmed this
the way I have the classes in case there's something in the unabridged
query that is an issue). One obvious problem is that it's trying to query
the specifications table without inserting the schema name.
select
bicycle0_.sll_id as sll1_0_3_,
bicycle0_2_.sll_date_created as sll2_0_3_,
bicycle0_2_.sll_date_updated as sll3_0_3_,
bicycle0_2_.sll_desc as sll4_0_3_,
bicycle0_2_.sll_title as sll5_0_3_,
bicycle0_1_.mfr_id as mfr2_1_3_,
bicycle0_.btp_id as btp2_2_3_,
manufactur1_.mfr_id as mfr1_4_0_,
manufactur1_.mfr_name as mfr2_4_0_,
specificat2_.sll_id as sll1_5_,
specificat3_.spc_id as spc2_5_,
(select
a9.spc_classname
from
specifications a9
where
a9.spc_id=specificat2_.spc_id) as formula0_5_,
specificat3_.spc_id as spc2_5_1_,
specificat3_.spc_classname as spc1_5_1_,
specificat3_1_.dec_value as dec1_6_1_,
specificat3_2_.bol_value as bol1_7_1_,
specificat3_3_.int_value as int1_8_1_,
specificat3_4_.str_value as str1_9_1_,
bicycletyp4_.btp_id as btp1_3_2_,
bicycletyp4_.btp_name as btp2_3_2_
from
sellable.bicycles bicycle0_
inner join
sellable.products bicycle0_1_
on bicycle0_.sll_id=bicycle0_1_.sll_id
inner join
sellable.sellables bicycle0_2_
on bicycle0_.sll_id=bicycle0_2_.sll_id
left outer join
sellable.manufacturers manufactur1_
on bicycle0_1_.mfr_id=manufactur1_.mfr_id
left outer join
sellable.productspecifications specificat2_
on bicycle0_.sll_id=specificat2_.sll_id
left outer join
sellable.specifications specificat3_
on specificat2_.spc_id=specificat3_.spc_id
left outer join
sellable.specdecimalvalues specificat3_1_
on specificat3_.spc_id=specificat3_1_.spc_id
left outer join
sellable.specbooleanvalues specificat3_2_
on specificat3_.spc_id=specificat3_2_.spc_id
left outer join
sellable.specintegervalues specificat3_3_
on specificat3_.spc_id=specificat3_3_.spc_id
left outer join
sellable.specstringvalues specificat3_4_
on specificat3_.spc_id=specificat3_4_.spc_id
left outer join
sellable.bicycletypes bicycletyp4_
on bicycle0_.btp_id=bicycletyp4_.btp_id
where
bicycle0_.sll_id=?
The problem is in the sub-query, which isn't getting a schema prepended to
the specifications table name.
If anyone knows how to either get the query to be correct, or of using the
class name directly as the Java map key, I'd appreciate being told.
Orthographic camera and selecting objects with raycast
Orthographic camera and selecting objects with raycast
I am running into a bit of difficulty selecting objects with the
orthographic camera using the raycaster. Though, I have no problem with it
when I use a perspective camera. The only thing I am changing when
switching between the two is the type camera.
I am able to select faces on the orthographic view, but it is only loosely
related to where I am clicking on the screen. When I can click far away
from the object and it will still come back as if it has hit the object
near its center.
Any ideas on what I am missing here?
I am basing much of my code on this example, and am hoping to achieve a
very similar result from my code. (this example I'm referencing uses the
perspective camera)
Any help is much appreciated
<html>
<head>
<style>
canvas {
left: 0;
top: 0;
width: 100%;
height: 100%;
position: fixed;
background-color: #111115;
}
</style>
</head>
<body id='c'>
<script src="js/three.js"></script>
<script>
var obj = [];
var mouse ={};
var zoom = 2;
var scene = new THREE.Scene();
//switch between these two and see the difference:
//var camera = new THREE.OrthographicCamera(window.innerWidth /
-zoom, window.innerWidth / zoom, window.innerHeight / zoom,
window.innerHeight / -zoom, -1000, 1000);
var camera = new THREE.PerspectiveCamera( 45, window.innerWidth /
window.innerHeight, 1, 1000 );
camera.position = new THREE.Vector3(100,100,100);
camera.lookAt(new THREE.Vector3(0,0,0));
// this material causes a mesh to use colors assigned to faces
var material = new THREE.MeshBasicMaterial(
{ color: 0xffffff, vertexColors: THREE.FaceColors } );
var sphereGeometry = new THREE.SphereGeometry( 80, 32, 16 );
for ( var i = 0; i < sphereGeometry.faces.length; i++ )
{
face = sphereGeometry.faces[ i ];
face.color.setRGB( 0, 0, 0.8 * Math.random() + 0.2 );
}
obj['box'] = {};
obj['box'] = new THREE.Mesh( sphereGeometry, material );
obj['box'].castShadow = true;
obj['box'].receiveShadow = true;
scene.add(obj['box']);
var ambientLight = new THREE.AmbientLight(0xbbbbbb);
scene.add(ambientLight);
var directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(-100, 40, 100);
directionalLight.castShadow = true;
directionalLight.shadowOnly = true;
directionalLight.shadowDarkness = .5;
scene.add(directionalLight);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
document.body.appendChild(renderer.domElement);
projector = new THREE.Projector();
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
function onDocumentMouseDown( event ) {
// the following line would stop any other event handler from firing
// (such as the mouse's TrackballControls)
// event.preventDefault();
console.log("Click.");
// update the mouse variable
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
// find intersections
// create a Ray with origin at the mouse position
// and direction into the scene (camera direction)
var vector = new THREE.Vector3( mouse.x, mouse.y, 1 );
projector.unprojectVector( vector, camera );
var ray = new THREE.Raycaster( camera.position, vector.sub(
camera.position ).normalize() );
// create an array containing all objects in the scene with which
the ray intersects
var intersects = ray.intersectObjects( [obj['box']] );
// if there is one (or more) intersections
if ( intersects.length > 0 )
{
console.log("Hit @ " + toString( intersects[0].point ) );
console.log(intersects);
// change the color of the closest face.
intersects[ 0 ].face.color.setRGB( 0.8 * Math.random() + 0.2, 0, 0 );
intersects[ 0 ].object.geometry.colorsNeedUpdate = true;
}
}
function toString(v) { return "[ " + v.x + ", " + v.y + ", " + v.z + "
]"; }
var render = function() {
requestAnimationFrame(render);
renderer.render(scene, camera);
};
console.log(camera);
console.log(obj['box'])
render();
</script>
</body>
I am hoping it is something simple that I just don't know about yet.
three.js r60
I am running into a bit of difficulty selecting objects with the
orthographic camera using the raycaster. Though, I have no problem with it
when I use a perspective camera. The only thing I am changing when
switching between the two is the type camera.
I am able to select faces on the orthographic view, but it is only loosely
related to where I am clicking on the screen. When I can click far away
from the object and it will still come back as if it has hit the object
near its center.
Any ideas on what I am missing here?
I am basing much of my code on this example, and am hoping to achieve a
very similar result from my code. (this example I'm referencing uses the
perspective camera)
Any help is much appreciated
<html>
<head>
<style>
canvas {
left: 0;
top: 0;
width: 100%;
height: 100%;
position: fixed;
background-color: #111115;
}
</style>
</head>
<body id='c'>
<script src="js/three.js"></script>
<script>
var obj = [];
var mouse ={};
var zoom = 2;
var scene = new THREE.Scene();
//switch between these two and see the difference:
//var camera = new THREE.OrthographicCamera(window.innerWidth /
-zoom, window.innerWidth / zoom, window.innerHeight / zoom,
window.innerHeight / -zoom, -1000, 1000);
var camera = new THREE.PerspectiveCamera( 45, window.innerWidth /
window.innerHeight, 1, 1000 );
camera.position = new THREE.Vector3(100,100,100);
camera.lookAt(new THREE.Vector3(0,0,0));
// this material causes a mesh to use colors assigned to faces
var material = new THREE.MeshBasicMaterial(
{ color: 0xffffff, vertexColors: THREE.FaceColors } );
var sphereGeometry = new THREE.SphereGeometry( 80, 32, 16 );
for ( var i = 0; i < sphereGeometry.faces.length; i++ )
{
face = sphereGeometry.faces[ i ];
face.color.setRGB( 0, 0, 0.8 * Math.random() + 0.2 );
}
obj['box'] = {};
obj['box'] = new THREE.Mesh( sphereGeometry, material );
obj['box'].castShadow = true;
obj['box'].receiveShadow = true;
scene.add(obj['box']);
var ambientLight = new THREE.AmbientLight(0xbbbbbb);
scene.add(ambientLight);
var directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(-100, 40, 100);
directionalLight.castShadow = true;
directionalLight.shadowOnly = true;
directionalLight.shadowDarkness = .5;
scene.add(directionalLight);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
document.body.appendChild(renderer.domElement);
projector = new THREE.Projector();
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
function onDocumentMouseDown( event ) {
// the following line would stop any other event handler from firing
// (such as the mouse's TrackballControls)
// event.preventDefault();
console.log("Click.");
// update the mouse variable
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
// find intersections
// create a Ray with origin at the mouse position
// and direction into the scene (camera direction)
var vector = new THREE.Vector3( mouse.x, mouse.y, 1 );
projector.unprojectVector( vector, camera );
var ray = new THREE.Raycaster( camera.position, vector.sub(
camera.position ).normalize() );
// create an array containing all objects in the scene with which
the ray intersects
var intersects = ray.intersectObjects( [obj['box']] );
// if there is one (or more) intersections
if ( intersects.length > 0 )
{
console.log("Hit @ " + toString( intersects[0].point ) );
console.log(intersects);
// change the color of the closest face.
intersects[ 0 ].face.color.setRGB( 0.8 * Math.random() + 0.2, 0, 0 );
intersects[ 0 ].object.geometry.colorsNeedUpdate = true;
}
}
function toString(v) { return "[ " + v.x + ", " + v.y + ", " + v.z + "
]"; }
var render = function() {
requestAnimationFrame(render);
renderer.render(scene, camera);
};
console.log(camera);
console.log(obj['box'])
render();
</script>
</body>
I am hoping it is something simple that I just don't know about yet.
three.js r60
Python - split sentence after words but with maximum of n characters in result
Python - split sentence after words but with maximum of n characters in
result
It seems I am too stupid to figure this out by myself:
I want to display some text on a scrolling display with a width of 16
characters. To improve readability I want to flip through the text, but
not by simply splitting every 16. character, I rather want to split on
every ending of a word or punctuation, before the 16 character limit
exceeds..
Example:
text = 'Hello, this is an example of text shown in the scrolling display.
Bla, bla, bla!'
this text shall be converted in a list of strings with 16 characters maximum
result = ['Hello, this is ', 'an example of ', 'text shown in ', 'the
scrolling ', 'display. Bla, ', 'bla, bla!']
I started with the regex re.split('(\W+)', text) to get a list of every
element (word, punctuation), but I fail combining them.
Can you help me, or at least give me some hints?
Thank you!
result
It seems I am too stupid to figure this out by myself:
I want to display some text on a scrolling display with a width of 16
characters. To improve readability I want to flip through the text, but
not by simply splitting every 16. character, I rather want to split on
every ending of a word or punctuation, before the 16 character limit
exceeds..
Example:
text = 'Hello, this is an example of text shown in the scrolling display.
Bla, bla, bla!'
this text shall be converted in a list of strings with 16 characters maximum
result = ['Hello, this is ', 'an example of ', 'text shown in ', 'the
scrolling ', 'display. Bla, ', 'bla, bla!']
I started with the regex re.split('(\W+)', text) to get a list of every
element (word, punctuation), but I fail combining them.
Can you help me, or at least give me some hints?
Thank you!
How to insert 1000 rows at a time
How to insert 1000 rows at a time
I made Wpf appliaction. I want to test it with 1000 values in grid. I want
to check that whether my grid will load 1000 data records fastly or not.
So how to write one query to insert more than 1000 records in my database
table. can i use for loop.
Insert into db(@names,@email,@password) Values('abc','def','mypassword');
I am using Sql-Server 2012 and ADO.net Connectivity! I want to execute
this query in database to generate 1000 rows
I made Wpf appliaction. I want to test it with 1000 values in grid. I want
to check that whether my grid will load 1000 data records fastly or not.
So how to write one query to insert more than 1000 records in my database
table. can i use for loop.
Insert into db(@names,@email,@password) Values('abc','def','mypassword');
I am using Sql-Server 2012 and ADO.net Connectivity! I want to execute
this query in database to generate 1000 rows
Subscribe to:
Comments (Atom)