Accessing a hyperlink from a SQL query - sql

I have a react application linked up to a PostgreSQL database. I'm using pgAdmin to insert my data. I have many rows but one of the fields in the row contains a link, and I want to be able access this link in my react application. Example query:
UPDATE myTable
SET body='Learn about React here'
WHERE ID = 1;
I have no issues displaying my data in react but it displays the HTML tags, which is not what I want.
Am I going about this the right way? Or should I remove the hyper link from the query and create an algorithm or regex expression to search for word here and attach <a href> tags to it?

Related

Dynamic SQL Server query in Powerapps

I have created a simple form in Powerapps which has a text input field called name and a data table which shows a list of all customers from a table called customer in a SQL Server database and I have also added a button labelled "Go" on the form.
What I want to do is:
See a blank data table when I first open the form
I would enter a customer name in the name text input field
Click the "Go" button and then the value from the name field will be passed to the SQL Server database in a query which only returns
the records which have the same name
Display the results of the query in the data table.
How can I do this?
Thanks
Assuming you've been able to correctly add your on-premise SQL server as a data source:
You'll want to use a combination of Collect() and Filter()
Assign your user input to a variable using (this isn't strictly necessary)
GetContext({UserVariable: TextInput.Text})
Use a combination of Collect() to store the data you pull from MSSQL, and Filter() to, well, filter the data.
Collect(AppStorageTable1, Filter('[dbo].SqlTable]', ColumnName1 = UserVariable))
If you assign AppStorageTable1 as your data source for your data table, it should now appear. (Note, you'll have to declare/create it before it will appear as an option, but once you've used the name in Collect() it will appear as a data source).
EDIT: The term you likely were looking for is "delegable", a quick search will yield a few articles about it. The "Filter" function will pass the work off to your SQL server, so your app won't be responsible for processing/filtering the data.

SQL select by field acting weird

I am writing this post because I have encountered something truly weird with an SQL statement I am trying to make.
Context:
I am developing an app which uses JPA in the backend to persist / retrieve objects to/from a postgres database.
Problem:
During some tests I have noticed that when a particular user adds entries in the database and later I try to fetch them by his facebook id, the result is an empty list, even though the entries are there in the database. Doing a select statement on the database returns no rows. This does not happen with other users.
I have noticed that the mentioned user's facebook id is slightly longer then others. I do not know if and how this affects this situation.
Interesting part:
When during debugging I created an entry not programmatically, but manually with a SQL INSERT statement directly on the database (marked red on the 1st screenshot), I could fetch the data by facebook id both in my app and with a select statement.
Do you have any ideas what is going on here?
Please check the screenshots:
result of select * from table:
result of select * from table where user_facebook_id = 10215905779020408 :
Please help,
Thanks

Why does this dropdown form filter work on a native table but not an ODBC linked table?

I'm transitioning an Access user app from using native Access tables to using ODBC-linked SQL Server tables.
I have a set of forms that are filtered by a selection from a dropdown (in a stand-alone selection form). By design, if the user leaves the dropdown blank the form launches unfiltered.
All of this works with the native tables, but when I try it using the linked tables I get an ODBC--call failed error
The SQL query Access generated for the query I'm using as the Record Source of the form that is filtered is:
SELECT linked.ASSIGNED_CARE_COORDINATOR, [rest of the variables]
WHERE (((linked.ASSIGNED_CARE_COORDINATOR)=[Forms]![frmCoord_Selector]![cmbCoords]))
OR (((([linked].[ASSIGNED_CARE_COORDINATOR])
Like [Forms]![frmDeadline_Report_Coord_Selector]![cmbCoords]) Is Null));
I know the ODBC connection itself is fine; if I remove the code after OR the query works with the linked table, but of course doesn't have the show-all-if-null functionality.
Why would this work with a native table but not the linked version of the exact same table?
The problem is the LIKE in the OR clause, but Access can apparently run that strange code on native tables. The correct code that will result in the desired behavior regardless of linked or native table is thus:
SELECT linked.ASSIGNED_CARE_COORDINATOR, [rest of the variables]
FROM linked
WHERE ((linked.ASSIGNED_CARE_COORDINATOR)=[Forms]![frmCoord_Selector]![cmbCoords])
OR [Forms]![frmCoord_Selector]![cmbCoords] Is Null

ColdFusion generate code to create database table

Im currently building an app to help with day to day development of our app development team.
Im wondering is there any sort of easy way to generate code to generate SQL tables that have already been created for MSSQL ?
I ask this because in MSSQL you can right click a table and choose the generate scripts option and it will create the code neccessary to build that particular table ?
Is there any way via SQL to leverage that function, or anyway within ColdFusion to create this code, without having to write it from scratch ?
I would use something like this SQL server query to get the list of columns in a table along with Data types, NOT NULL, and PRIMARY KEY constraints to get the table names and columns and data types and construct something with the results to write a script for creating the tables.
You can right click and generate the script from SQL. Then in CF, you can have something like this:-
<cfquery name = "query1" dataSource = "ds1">
type in the generated script from SQL here
</cfquery>`

Remove text from within a database text field

I recently tried to import a bunch of blog posts from an old blog (SharePoint) to my current blog (WordPress). When the import completed, a lot of nasty <div> tags and other HTML made it in to the content of the post, which screwed up the way my site was rendering.
I'm able to view the offending rows in the MySQL database and want to know if there's a way to selectively remove the HTML text that may be causing problems. I could probably hack this in C# by parsing through the text, but I'd like to figure out how I can do this using SQL if I can.
If you want to see a full text sample of what one of these files looks like as it exists in the database text field, I uploaded a full sample file to my web site.
Here's want I want to do:
Remove <![CDATA[<div><b>Body:</b> from the beginning of every file
Remove the meta information at the end of every file, which might look like this:
<div><b>Category:</b> SharePoint</div>
<div><b>Published:</b> 11/12/2007 11:26 AM</div>
]]>
Remove every <div> and closing </div> tag, which might have a class attribute like:
<div class=ExternalClass6BE1B643F13346DF8EFC6E53ECF9043A>
Note: The hex string at the end of the ExternalClass can be different
I haven't used an Update statement in MySQL before and I'm at a loss for where to begin to selectively replace text within a text field. Would I use regex from within a SQL statement to help? How would I execute a statement against the remote DB?
What about cleaning up the posts before you import them? Seems like working with a local file that you can treat as a text file would be far easier. Then you could use Perl or Python to bear down on the problem to your liking before importing.
This assumes that you still have access to the data that was over in SharePoint.
There is no simple way of doing this without utilizing the back-end platform which you are using to serve your website or are most acustomed to. Myself, I would use PHP or Perl to clean the data up which will could be tricky at best. So the answer is, it can be done, but you must use some type of programming/processing language to do so, MySQL on its own won't be able to clean the data.
Assuming you are determined to use SQL like you said in your question, If you have the skill to hack it with C# you should be able to figure out how to create a stored procedure that uses a cursor in a repeat/fetch loop to select the rows, string functions to massage the data, and an update to update the row. Check this out:
http://dev.mysql.com/doc/refman/5.0/en/cursors.html