DB2 not saving stylized apostrophe (’) - character-encoding

I am trying to insert a stylized apostrophe (’) into a table in DB2 LUW 9.7. Every method I have tried has resulted in it being a square () when selected back.
The methods I have tried to insert it:
Modifying and committing a row in Control Center (GUI)
Updating a row via SQL command in Command Editor
Loading from a file (both UTF-8 encoded and ANSI encoded) through IBM Data Studio 2.2
Is there a way to get this character into the database? If not, is there a list of characters that simply cannot be used?

What is the encoding of your database/tablespace? I suspect it needs to be set to UTF-8. You may need to create a new tablespace or recreate the database with the encoding explicitly set to UTF-8.
To determine the encoding, run the following command and look for the "Code set" information:
db2 get db cfg for <database name>

from Inserting an Apostrophe in DB2 table
insert into userid.empy values(1234,'RAM''');
You have put 2 Single Quotations, for a single quote to appear in the
table.
see also:
http://www.ibmmainframes.com/viewtopic.php?t=36901&highlight=apostrophe and
http://www.ibmmainframes.com/viewtopic.php?t=29213&highlight=apostrophe

if you are using the API, a good way is to prepare the statement and bind the quote-containing text to a parameter.
Remind that allowing someone to type in a quote and insert that unchanged (like sprintf(sqlstr, "INSERT INTO mytable VALUES ('%s')", inputstr);) may lead to an SQL-Injection.
my input:
test');drop database;insert into mytable values ('test
may lead to an empty database

Related

How to display geometry datafield as Text

I'm using DELPHI with ADO and SQL Server 2014.
In our database table there is a spatial column for geometrical data. We can read and write data to this field (more info is here : https://learn.microsoft.com/de-de/sql/relational-databases/spatial/spatial-data-sql-server).
If I display this table using a TDBGRID component I got only (BLOB) shown for the content of this column in my table.
Now I want to see the content of this column. Is the any good coding to show the content of this column e.g. in a dbmemo as text.
The only solution I know is to read the field as text into a string and put this to a normal memo, I'm looking forward to get a more efficient method to access this data
You can query e.g. for Well-known text format by using SQL function like STAsText:
SELECT MyColumn.STAsText() FROM MyTable
An alternative would be fetching your data in Well-known binary data stream with parsing it on the client side to represent as text by yourself (the format is described). For fetching such stream you'd use STAsBinary function:
SELECT MyColumn.STAsBinary() FROM MyTable
Yet another option would be fetching raw geometry data as they are stored in database (as you do right now) and parse it by yourself. The format is described in the [MS-SSCLRT] document. But if I were you I would better write parser for the WKB format and fetch data in WKB format because it's quite established universal format, whilst SQL Server internal formats may change frequently.
In case your geometry includes Z and / or M values it is better to call .ToString () method.
SELECT MyColumn.ToString () FROM MyTable
The output includes Z and M values in addition to X,Y Coordinates. The .STAsText() method returns only the X,Y coordinates of your shape.

Force field/tag when inserting data on influxdb

I am just starting with influxdb as a time series database and i was trying to create some measurements, however it seems like influx automatically determines which fields of the measurements are tags and which are fields, is there any way to force one or another at insertion time (first insertion of a measurement)?? or any other way whatsoever?
No, InfluxDB won't automatically determine which are fields and which are tags. Your "insert string" structure "helps InfluxDB in determining which are tags and which are fields.
For example:
cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000
In this string, "cpu_load_short" is the measurment name (observe that there is no = sign to form a key/value pair), followed by semi colon.
host=server01,region=us-west are tags (in key value formats)
Rignt after tags you can see that there is space, which tells following the space are "Fields".
You may refer this documentation for more information.

Why does the result set of Informix automatically add blank spaces to the varchar fields?

Why does the result set of Informix automatically add blank spaces to the varchar fields?
The trim function is no use. When inserting such result set into another DB, it would also contain the blank spaces.
How to filter or trim the blank spaces?
If you have a database varchar(n) field, and there are blank chars on the right of the text, they are coming from the application layer, not the engine. (For example, your column is defined as varchar(30) and your application form/screen has a text field of (30).) If the application layer does not provide a varchar field, you might see this.
Take note this is not only valid for Informix; it is valid for any transactional database engine.

Store Arabic character in Netezza N3001

I have Arabic data in my source DB2 database. I am using DataStage as ETL tool and my target is Netezza. On loading the data I am seeing '???' in Datastage and in Netezza as well.
Please guide me on how to read the data in Netezza and in Datastage and what all encoding to use .
Thanks in advance.
Regards,
Gnanesh
Looks like you're just using varchar columns instead of nvarchar columns. After putting some Arabic characters in a file,
create table so as select * from external '/home/nz/test.dat' (arabic nvarchar(100));
Selecting from this new table returns the characters.

Crystal Reports parameterized queries

The company I work for is using MacolaES for an ERP system. The SQL Server database is structured such that when things are no longer considered active, they are moved from a set of "active" tables to a set of "history" tables. This helps to keep the "active" tables small enough that queries return quickly. On the flip side, the history tables are enormous. The appropriate columns are indexed in these tables, and if you query for something specific it returns quickly.
The problem is when you make a Crystal Report, which is prompting the user for a parameter. For reasons not known to me, Crystal parameters are not translated into SQL parameters, so you end up with queries selecting everything from the order header history table inner joined to everything in the order lines history table, which results in over 8 million rows.
Is there a way to get Crystal Reports to use the parameters in the SQL query instead of loading all the records and filtering after the fact? I read somewhere that a stored procedure should work, but I'm curious if an ordinary parameterized query is possible in the interest of saving my time.
Here is the selection formula:
(
trim({Orderheader.ord_no}) = {?Order No}
)
and
(
{Orderheader.ord_type} = 'O'
)
and
(
{orderlines.ord_type} = 'O'
)
In Crystal Reports top menu go to Report / Selection Formulas / Record... There you can add a formula similar to:
{table.field1} = {?Parameter1} and {table.field2} = {?Parameter2}
That will add the condition to the where statement of the SQL query that the report will use to pull the rows.
To verify what is the condition in the where statement that the report is using to pull the data you can go to the menu database / Show SQL Statement. That way you can verify that the report is using the parameters in the filter.
Crystal Reports 8.5 User Guide mention the following tips:
To push down record selection, you
must select “Use Indexes or Server for
Speed” in the Report Options dialog
box (available on the File menu).
In record selection formulas, avoid data
type conversions on fields that are
not parameter fields. For example,
avoid using ToText( ) to convert a
numeric database field to a string
database field.
You are able to push down some record selection formulas
that use constant expressions.
Your formula has a TRIM function on a field. The function against the field does not allow Crystal to push the formula to the database because is not a constant expression.
If you really need to trim the order number field you should do it using SQL Expressions.
References:
Check out this article.

Resources