问:
NoSuchTableException being thrown from dbunit test cases
I'm trying to fix the test suite on an project which I've inherited from another programmer for some java database code.  The project itself is using hibernate and MySQL for the DB stuff, but for the purposes of the test cases dbunit is being used.  I can correctly load and initialize hibernate's session factory, but I keep getting exceptions when I try to run my tests in Eclipse, namely "org.dbunit.dataset.NoSuchTableException: mytablename".

I know that all the files are in the right place, and that the actual XML file I'm passing into dbunit is ok (I'm using the FlatXmlDataSet type).  My setUp() method in the database test case base class looks like this:

```<code>@Override
protected void setUp() throws Exception {
    super.setUp();
    IDataSet dataSet = new FlatXmlDataSet(new File(mDataFile));

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    IDatabaseConnection connection = new DatabaseConnection(session.connection());

    DatabaseConfig config = connection.getConfig();
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

    DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);

    session.getTransaction().commit();
}
</code>```

Right after the CLEAN_INSERT database operation, the exception gets thrown complaining about the last table in my XML file, regardless of which table this is.  I have verified the DTD and XML schema by hand and with Eclipse, even going to the point of making sure the ordering of the tables in the two files matched.  I'd rather not paste those files in here (as it would involve a lot of search-replacing), but trust me that I've looked through dbunit examples and made sure that the syntax matches.

Any ideas on what could be wrong?  I've been googling for hours and can't come up with anything useful.

Edit: One thing I forgot to mention, is that when I place a breakpoint at the line which throws, I can look through dataSet's structure and see that all of my tables are actually in there, along with all of the test data.  So at least that part seems to be working correctly.

@Bogdan: Hrm... good idea.  I'll try loading the data with a regular INSERT.
@sleske: Also a good suggestion.  Thanks for the hints; hopefully this will set me on the right path to fixing this problem.

答:
More information is needed to solve this.

Have you tried to debug this? You can put DBUnit's source code as a separat project into your Eclipse workspace. Then configure your test's "build path" to use the DBUnit project instead of a dbunit.jar. That way you can debug into DBUnit's code. Then you'll hopefully see why it throws an exception.

OwnerDisplayName: sqook

ContentLicense: CC BY-SA 2.5

Body:
I'm trying to fix the test suite on an project which I've inherited from another programmer for some java database code.  The project itself is using hibernate and MySQL for the DB stuff, but for the purposes of the test cases dbunit is being used.  I can correctly load and initialize hibernate's session factory, but I keep getting exceptions when I try to run my tests in Eclipse, namely "org.dbunit.dataset.NoSuchTableException: mytablename".

I know that all the files are in the right place, and that the actual XML file I'm passing into dbunit is ok (I'm using the FlatXmlDataSet type).  My setUp() method in the database test case base class looks like this:

@Override
protected void setUp() throws Exception {
    super.setUp();
    IDataSet dataSet = new FlatXmlDataSet(new File(mDataFile));

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    IDatabaseConnection connection = new DatabaseConnection(session.connection());

    DatabaseConfig config = connection.getConfig();
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

    DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);

    session.getTransaction().commit();
}

Right after the CLEAN_INSERT database operation, the exception gets thrown complaining about the last table in my XML file, regardless of which table this is.  I have verified the DTD and XML schema by hand and with Eclipse, even going to the point of making sure the ordering of the tables in the two files matched.  I'd rather not paste those files in here (as it would involve a lot of search-replacing), but trust me that I've looked through dbunit examples and made sure that the syntax matches.

Any ideas on what could be wrong?  I've been googling for hours and can't come up with anything useful.

Edit: One thing I forgot to mention, is that when I place a breakpoint at the line which throws, I can look through dataSet's structure and see that all of my tables are actually in there, along with all of the test data.  So at least that part seems to be working correctly.

@Bogdan: Hrm... good idea.  I'll try loading the data with a regular INSERT.
@sleske: Also a good suggestion.  Thanks for the hints; hopefully this will set me on the right path to fixing this problem.

LastEditorDisplayName: sqook

OwnerDisplayName: sleske


来源: stackexchange

问:
How to change the color of the HyperLink in ASP.NET
i am doing mini ERP project., in that i have 3 frames.
frame is used as Header where i have "Home" and "logout" image button
when i click "Home" the frame3 goes to Home page and when i click "Logout" button, all the frames disappears and main window of "Login" screen comes.
i have used "Home " and "Logout" button in image using Hyperlink control in ASP.NET
the problem is due to Hyperlink the button gets blue border around it.
i want to remove that border around the image button.
can any one knows how to remove that border
here my codes

```<code><asp:HyperLink ID="HomeButtonlink"
    BorderWidth="0px"
    Font-Overline = "False"
    ImageUrl="~/Images/Untitled-5.png"
    runat="server"
    Height="100%"
    Target ="frame3"
    NavigateUrl="~/About.aspx"
    BorderStyle="None"></asp:HyperLink>
</code>```

thanks in advances
A.S.Rajkumar.Rajguru

答:
The border around images that are links is part of the default HTML stylesheet.

To get rid of it for all images, add a simple bit of CSS to your page as follows:

```<code>img {border:none;}
</code>```

This is a common thing to want to do, as very few people actually want the default behaviour these days. You may want to look into adding a 'reset' stylesheet to your site to get rid of all the unwanted default behaviours. It will also make your page work more consistently between different browers.

Here's a link to a related question to help you find out more: https://stackoverflow.com/questions/116754/best-css-reset

If for some reason you don't want to affect all the image links on your site, you could also do a more specific stylesheet for it since you've given it an ID:

```<code>#HomeButtonlink {border:none;}
</code>```

You could also add a CSS class to the object, and then reference that in your stylesheet if you wanted to apply it to a group of buttons.

...but frankly, I'd just go with the full reset if I were you.

ContentLicense: CC BY-SA 3.0

Body:
i am doing mini ERP project., in that i have 3 frames.
frame is used as Header where i have "Home" and "logout" image button
when i click "Home" the frame3 goes to Home page and when i click "Logout" button, all the frames disappears and main window of "Login" screen comes.
i have used "Home " and "Logout" button in image using Hyperlink control in ASP.NET
the problem is due to Hyperlink the button gets blue border around it.
i want to remove that border around the image button.
can any one knows how to remove that border
here my codes

<asp:HyperLink ID="HomeButtonlink"
    BorderWidth="0px"
    Font-Overline = "False"
    ImageUrl="~/Images/Untitled-5.png"
    runat="server"
    Height="100%"
    Target ="frame3"
    NavigateUrl="~/About.aspx"
    BorderStyle="None"></asp:HyperLink>

thanks in advances
A.S.Rajkumar.Rajguru

Body:
The border around images that are links is part of the default HTML stylesheet.

To get rid of it for all images, add a simple bit of CSS to your page as follows:

img {border:none;}

This is a common thing to want to do, as very few people actually want the default behaviour these days. You may want to look into adding a 'reset' stylesheet to your site to get rid of all the unwanted default behaviours. It will also make your page work more consistently between different browers.

Here's a link to a related question to help you find out more: https://stackoverflow.com/questions/116754/best-css-reset

If for some reason you don't want to affect all the image links on your site, you could also do a more specific stylesheet for it since you've given it an ID:

#HomeButtonlink {border:none;}

You could also add a CSS class to the object, and then reference that in your stylesheet if you wanted to apply it to a group of buttons.

...but frankly, I'd just go with the full reset if I were you.


问:
Issue on trying to query GeoJson multipolygons in SQL Server 2016
I am trying to run a query (which I gleened from here) against GeoJson multipolygon data. It processes many of the spatial records but is stopping on a some.

I get the following error in the query messages:

Msg 6522, Level 16, State 1, Line 10

      A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":

      System.FormatException: 24142: Expected "(" at position 15. The input has ",".

      System.FormatException:

      at Microsoft.SqlServer.Types.WellKnownTextReader.RecognizeToken(Char token)     at Microsoft.SqlServer.Types.WellKnownTextReader.ParseLineStringText()

      at Microsoft.SqlServer.Types.WellKnownTextReader.ParsePolygonText()

      at Microsoft.SqlServer.Types.WellKnownTextReader.ParseMultiPolygonText()

      at Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type)

      at Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid)

      at Microsoft.SqlServer.Types.SqlGeography.ParseText(OpenGisType type, SqlChars taggedText, Int32 srid)

      at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)

This is my statement with some test data:

```<code>declare @CountiesGeoJson nvarchar(max) = '{"type":"FeatureCollection","features":[
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "700", "COUNTYNS": "01498555", "GEOID": "51700", "NAME": "Newport News" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-76.622252, 37.142146], [-76.577819, 37.187025], [-76.591432, 37.214721], [-76.565092, 37.220645], [-76.458516, 37.100661], [-76.435519, 37.094882], [-76.451274, 37.076878], [-76.442269, 37.018448], [-76.424757, 37.025107], [-76.387711304409194, 36.989671332859004], [-76.411768, 36.962847], [-76.428869, 36.969947], [-76.464471, 37.027547], [-76.518242, 37.055351], [-76.536875, 37.083942], [-76.564219, 37.077507], [-76.618252, 37.119347], [-76.622252, 37.142146]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "620", "COUNTYNS": "01498424", "GEOID": "51620", "NAME": "Franklin" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-76.963021, 36.704696], [-76.912221, 36.698408], [-76.909672, 36.648175], [-76.962339, 36.667515], [-76.949327, 36.67873], [-76.968027, 36.682971], [-76.963021, 36.704696]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "595", "COUNTYNS": "01498422", "GEOID": "51595", "NAME": "Emporia" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.557359, 36.713166], [-77.510273, 36.718229], [-77.509246, 36.682998], [-77.556524, 36.674874], [-77.557359, 36.713166]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "670", "COUNTYNS": "01498428", "GEOID": "51670", "NAME": "Hopewell" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.334549, 37.312468], [-77.273379, 37.316116], [-77.253234, 37.295668], [-77.31081, 37.261451], [-77.328291, 37.271748], [-77.334549, 37.312468]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "510", "COUNTYNS": "01498415", "GEOID": "51510", "NAME": "Alexandria" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.140872, 38.826905], [-77.110799, 38.843446], [-77.087805, 38.827357], [-77.085609, 38.84419], [-77.044487611898006, 38.839598699716696], [-77.040372554526996, 38.785355394851003], [-77.143135, 38.805321], [-77.140872, 38.826905]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "059", "COUNTYNS": "01480119", "GEOID": "51059", "NAME": "Fairfax" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.53576, 38.847474], [-77.32828109319901, 39.057794871536501], [-77.246003, 39.024909], [-77.255703, 39.002409], [-77.234803, 38.97631], [-77.148179, 38.965002], [-77.119759, 38.934343], [-77.172276, 38.893245], [-77.194712, 38.899073], [-77.194234, 38.886146], [-77.149701, 38.87567], [-77.110799, 38.843446], [-77.140872, 38.826905], [-77.143135, 38.805321], [-77.040372554526996, 38.785355394851003], [-77.042298, 38.718515], [-77.122001, 38.685816], [-77.1302, 38.635017], [-77.204302, 38.617817], [-77.277032, 38.695026], [-77.355884, 38.725425], [-77.370878, 38.710433], [-77.442956, 38.803796], [-77.492801, 38.797821], [-77.50834, 38.841032], [-77.53576, 38.847474]], [[-77.334852, 38.853737], [-77.318689, 38.834651], [-77.27052, 38.840902], [-77.270597, 38.866075], [-77.334852, 38.853737]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "680", "COUNTYNS": "01498429", "GEOID": "51680", "NAME": "Lynchburg" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-79.26745, 37.44744], [-79.183302, 37.465908], [-79.120451, 37.398311], [-79.085244, 37.394743], [-79.214924, 37.33258], [-79.257188, 37.355608], [-79.231933, 37.394911], [-79.256628, 37.406573], [-79.244548, 37.419941], [-79.268727, 37.431028], [-79.26745, 37.44744]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "037", "COUNTYNS": "01492442", "GEOID": "51037", "NAME": "Charlotte" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-78.902227, 37.026799], [-78.824209, 37.205361], [-78.808198, 37.201852], [-78.778353, 37.228639], [-78.734351, 37.220256], [-78.681477, 37.24969], [-78.692432, 37.203673], [-78.644621, 37.194323], [-78.634927, 37.170064], [-78.583642, 37.140635], [-78.547128, 37.150431], [-78.480891, 37.085196], [-78.443644, 37.079371], [-78.493028, 36.89122], [-78.648541, 36.697909], [-78.691328, 36.741847], [-78.666145, 36.764363], [-78.682652, 36.797222], [-78.666995, 36.811822], [-78.686878, 36.824331], [-78.666125, 36.840482], [-78.671463, 36.857951], [-78.749727, 36.920065], [-78.727686, 36.937454], [-78.743891, 37.005439], [-78.756549, 37.00717], [-78.748358, 36.987057], [-78.774715, 36.980976], [-78.785452, 36.952783], [-78.817455, 36.98402], [-78.892702, 36.976694], [-78.902227, 37.026799]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "099", "COUNTYNS": "01480137", "GEOID": "51099", "NAME": "King George" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.330384, 38.334951], [-77.286201505089011, 38.347024428844499], [-77.240072, 38.331598], [-77.17934, 38.341915], [-77.138224, 38.367917], [-77.08481, 38.368297], [-77.043526, 38.400548], [-77.011827, 38.374554], [-77.030683, 38.311623], [-76.99767, 38.278047], [-77.044799, 38.260407], [-77.048482, 38.182444], [-77.073796, 38.141331], [-77.084596, 38.160231], [-77.115997, 38.149931], [-77.2143, 38.197029], [-77.254001, 38.18943], [-77.242001, 38.210729], [-77.251801, 38.229628], [-77.229757, 38.245208], [-77.275302, 38.247528], [-77.291402, 38.223729], [-77.290302, 38.238728], [-77.309419, 38.234737], [-77.345728, 38.26139], [-77.330384, 38.334951]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "161", "COUNTYNS": "01480165", "GEOID": "51161", "NAME": "Roanoke" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-80.261984, 37.340694], [-80.200161, 37.378568], [-80.147625, 37.382342], [-80.073985, 37.422305], [-79.865099, 37.328417], [-79.840367, 37.302681], [-79.858058, 37.267138], [-79.847082, 37.225468], [-79.962301, 37.137099], [-80.030562, 37.17481], [-80.088553, 37.160482], [-80.128119, 37.122912], [-80.172264, 37.108156], [-80.189835, 37.233476], [-80.25852, 37.308344], [-80.261984, 37.340694]], [[-80.088062, 37.282334], [-80.050761, 37.252635], [-80.033464, 37.26289], [-80.02883, 37.24365], [-79.998113, 37.252193], [-79.950384, 37.211274], [-79.924496, 37.224634], [-79.900048, 37.257297], [-79.909493, 37.278054], [-79.879276, 37.304047], [-79.974023, 37.335419], [-80.022226, 37.308338], [-80.033596, 37.324293], [-80.12049, 37.287053], [-80.088062, 37.282334]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "135", "COUNTYNS": "01493928", "GEOID": "51135", "NAME": "Nottoway" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-78.238161, 37.194822], [-78.231234, 37.29622], [-77.795926, 37.192592], [-77.805982, 37.175933], [-77.900254, 37.143885], [-77.889813, 36.988818], [-77.932749, 36.984246], [-77.968114, 36.987292], [-78.003639, 37.022756], [-78.082023, 37.011121], [-78.172207, 37.055963], [-78.170716, 37.076188], [-78.224286, 37.089685], [-78.239354, 37.120089], [-78.238161, 37.194822]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "683", "COUNTYNS": "01498430", "GEOID": "51683", "NAME": "Manassas" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.526457, 38.732466], [-77.475711, 38.781214], [-77.44751, 38.761115], [-77.451642, 38.738337], [-77.471425, 38.728152], [-77.507299, 38.740479], [-77.506167, 38.705741], [-77.526457, 38.732466]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "630", "COUNTYNS": "01498425", "GEOID": "51630", "NAME": "Fredericksburg" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.530283, 38.309175], [-77.506782, 38.325925], [-77.467053, 38.31866], [-77.447126, 38.284614], [-77.457837, 38.271108], [-77.492045, 38.273637], [-77.530283, 38.309175]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "610", "COUNTYNS": "01498423", "GEOID": "51610", "NAME": "Falls Church" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.194712, 38.899073], [-77.172276, 38.893245], [-77.149701, 38.87567], [-77.189719, 38.87801], [-77.194712, 38.899073]]]] } },
]}';
--DECLARE @@CountiesGeoJson nvarchar(max)
--SELECT @@CountiesGeoJson = BulkColumn
--FROM OPENROWSET
--(BULK 'C:\MapData\countiesEdited.json', SINGLE_CLOB)
--as JSON

--Insert Into [Tox].[dbo].[GeoCounties] (GEOID, GEO_NAME, FIPS_ST_CD, FIPS_CNTY_CD, RESOLUTION_ACCURACY, GEO_OBJECT)
select GEOID, GNAME, STATEFP, COUNTYFP, 10, Geo=fixed
from   openjson (@CountiesGeoJson, '$.features')
with
(
    GEOID char(5) '$.properties.GEOID',
    GNAME varchar(40) '$.properties.NAME',
    STATEFP char(2) '$.properties.STATEFP',
    COUNTYFP char(3) '$.properties.COUNTYFP',
    [type] Varchar(64) '$.geometry.type',
    [coordinates] nvarchar(max) '$.geometry.coordinates' as json
)
as GeoData
cross apply (
select
   stuff(
      (
        select concat(',  ', json_value(Value,'$[0]'),' ',json_value(Value,'$[1]'))
        from openjson(GeoData.coordinates,'$[0]')
        order by cast([key] as int)
        for xml path('')
      ),1,3,'') [path]
) PolygonData
OUTER APPLY (
    SELECT  STUFF(
        (
            SELECT CONCAT(',  ', polygon)
            FROM OPENJSON(GeoData.coordinates) as Poly
            CROSS APPLY OPENJSON(Poly.value) as Shape
            CROSS APPLY (
                SELECT '(' + stuff(
                (
                    select concat(',  ', json_value(Value,'$[0]'),' ',json_value(Value,'$[1]'))
                    from OPENJSON(Shape.value)
                    order by cast([key] as int)
                    for xml path('')
                ),1,3,'')+')' polygon
        ) Polygons
        for xml path('')
    ),1,3,'') multi
    WHERE LEN(Path) = 0
) MultigonData
cross apply (
    SELECT concat(upper(GeoData.[type]),'((',IsNull(NULLIF(path,''),multi),'))') WKT
) shapeDef
outer apply (
    select geography::STGeomFromText(WKT,4326).MakeValid()/*.ReorientObject()*/ as geom
) geography
outer apply (
    select CASE WHEN geom.EnvelopeAngle() > 90 THEN geom.ReorientObject() ELSE geom END as fixed
) fixes
</code>```

The query will run and produce some results but when it hits records where the NAME = 'Fairfax' and 'Roanoke', it stops with the above error.

Can anyone see the issue and know how to resolve this?

[EDIT 2019-05-31 17:35]
GeoJson Header:

```<code>{
  "type": "FeatureCollection",
  "name": "USCounty_Simplify_01",
  "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::4269" } },
  "features": [
...
</code>```

答:
Thanks @Hank for taking this query for a spin! @Vitaly-Borisov has highlighted the specific offending geometry, this has helped immensely in solving the issue.

In the original Query, there is a CROSS APPLY query that creates a result set called PolygonData, immediately after that is an OUTER APLY that creates a result set called MultigonData.

Notice that MultigonData only has results WHERE LEN(Path) = 0

The expectation here was that all non polygon geometry would yield a null value for Path and so we only attempt to resolve the MultiPolygon WKT if the geometry was indeed a MultiPolygon type.

This query only supports Polygon and MultiPolygon types of geometry, it was a broad enough assumption that suited at that time.

Instead of using the failure to resolve a Polygon (WHERE LEN(Path) = 0) to determine that the geometry is in fact a MultiPolygon, we can use the type definition itself!

Updated Query, notice the where clauses within the PolygonData and MutigonData queries and the use of COALESCE in shapeDef

These minor changes should make it easier to adopt this logic for other geography types.

```<code>declare @CountiesGeoJson nvarchar(max) = '{ "type": "FeatureCollection", "name": "USCounty_Simplify_01", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::4269" } }, "features": [
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "700", "COUNTYNS": "01498555", "GEOID": "51700", "NAME": "Newport News" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-76.622252, 37.142146], [-76.577819, 37.187025], [-76.591432, 37.214721], [-76.565092, 37.220645], [-76.458516, 37.100661], [-76.435519, 37.094882], [-76.451274, 37.076878], [-76.442269, 37.018448], [-76.424757, 37.025107], [-76.387711304409194, 36.989671332859004], [-76.411768, 36.962847], [-76.428869, 36.969947], [-76.464471, 37.027547], [-76.518242, 37.055351], [-76.536875, 37.083942], [-76.564219, 37.077507], [-76.618252, 37.119347], [-76.622252, 37.142146]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "620", "COUNTYNS": "01498424", "GEOID": "51620", "NAME": "Franklin" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-76.963021, 36.704696], [-76.912221, 36.698408], [-76.909672, 36.648175], [-76.962339, 36.667515], [-76.949327, 36.67873], [-76.968027, 36.682971], [-76.963021, 36.704696]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "595", "COUNTYNS": "01498422", "GEOID": "51595", "NAME": "Emporia" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.557359, 36.713166], [-77.510273, 36.718229], [-77.509246, 36.682998], [-77.556524, 36.674874], [-77.557359, 36.713166]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "670", "COUNTYNS": "01498428", "GEOID": "51670", "NAME": "Hopewell" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.334549, 37.312468], [-77.273379, 37.316116], [-77.253234, 37.295668], [-77.31081, 37.261451], [-77.328291, 37.271748], [-77.334549, 37.312468]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "510", "COUNTYNS": "01498415", "GEOID": "51510", "NAME": "Alexandria" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.140872, 38.826905], [-77.110799, 38.843446], [-77.087805, 38.827357], [-77.085609, 38.84419], [-77.044487611898006, 38.839598699716696], [-77.040372554526996, 38.785355394851003], [-77.143135, 38.805321], [-77.140872, 38.826905]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "059", "COUNTYNS": "01480119", "GEOID": "51059", "NAME": "Fairfax" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.53576, 38.847474], [-77.32828109319901, 39.057794871536501], [-77.246003, 39.024909], [-77.255703, 39.002409], [-77.234803, 38.97631], [-77.148179, 38.965002], [-77.119759, 38.934343], [-77.172276, 38.893245], [-77.194712, 38.899073], [-77.194234, 38.886146], [-77.149701, 38.87567], [-77.110799, 38.843446], [-77.140872, 38.826905], [-77.143135, 38.805321], [-77.040372554526996, 38.785355394851003], [-77.042298, 38.718515], [-77.122001, 38.685816], [-77.1302, 38.635017], [-77.204302, 38.617817], [-77.277032, 38.695026], [-77.355884, 38.725425], [-77.370878, 38.710433], [-77.442956, 38.803796], [-77.492801, 38.797821], [-77.50834, 38.841032], [-77.53576, 38.847474]], [[-77.334852, 38.853737], [-77.318689, 38.834651], [-77.27052, 38.840902], [-77.270597, 38.866075], [-77.334852, 38.853737]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "680", "COUNTYNS": "01498429", "GEOID": "51680", "NAME": "Lynchburg" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-79.26745, 37.44744], [-79.183302, 37.465908], [-79.120451, 37.398311], [-79.085244, 37.394743], [-79.214924, 37.33258], [-79.257188, 37.355608], [-79.231933, 37.394911], [-79.256628, 37.406573], [-79.244548, 37.419941], [-79.268727, 37.431028], [-79.26745, 37.44744]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "037", "COUNTYNS": "01492442", "GEOID": "51037", "NAME": "Charlotte" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-78.902227, 37.026799], [-78.824209, 37.205361], [-78.808198, 37.201852], [-78.778353, 37.228639], [-78.734351, 37.220256], [-78.681477, 37.24969], [-78.692432, 37.203673], [-78.644621, 37.194323], [-78.634927, 37.170064], [-78.583642, 37.140635], [-78.547128, 37.150431], [-78.480891, 37.085196], [-78.443644, 37.079371], [-78.493028, 36.89122], [-78.648541, 36.697909], [-78.691328, 36.741847], [-78.666145, 36.764363], [-78.682652, 36.797222], [-78.666995, 36.811822], [-78.686878, 36.824331], [-78.666125, 36.840482], [-78.671463, 36.857951], [-78.749727, 36.920065], [-78.727686, 36.937454], [-78.743891, 37.005439], [-78.756549, 37.00717], [-78.748358, 36.987057], [-78.774715, 36.980976], [-78.785452, 36.952783], [-78.817455, 36.98402], [-78.892702, 36.976694], [-78.902227, 37.026799]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "099", "COUNTYNS": "01480137", "GEOID": "51099", "NAME": "King George" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.330384, 38.334951], [-77.286201505089011, 38.347024428844499], [-77.240072, 38.331598], [-77.17934, 38.341915], [-77.138224, 38.367917], [-77.08481, 38.368297], [-77.043526, 38.400548], [-77.011827, 38.374554], [-77.030683, 38.311623], [-76.99767, 38.278047], [-77.044799, 38.260407], [-77.048482, 38.182444], [-77.073796, 38.141331], [-77.084596, 38.160231], [-77.115997, 38.149931], [-77.2143, 38.197029], [-77.254001, 38.18943], [-77.242001, 38.210729], [-77.251801, 38.229628], [-77.229757, 38.245208], [-77.275302, 38.247528], [-77.291402, 38.223729], [-77.290302, 38.238728], [-77.309419, 38.234737], [-77.345728, 38.26139], [-77.330384, 38.334951]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "161", "COUNTYNS": "01480165", "GEOID": "51161", "NAME": "Roanoke" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-80.261984, 37.340694], [-80.200161, 37.378568], [-80.147625, 37.382342], [-80.073985, 37.422305], [-79.865099, 37.328417], [-79.840367, 37.302681], [-79.858058, 37.267138], [-79.847082, 37.225468], [-79.962301, 37.137099], [-80.030562, 37.17481], [-80.088553, 37.160482], [-80.128119, 37.122912], [-80.172264, 37.108156], [-80.189835, 37.233476], [-80.25852, 37.308344], [-80.261984, 37.340694]], [[-80.088062, 37.282334], [-80.050761, 37.252635], [-80.033464, 37.26289], [-80.02883, 37.24365], [-79.998113, 37.252193], [-79.950384, 37.211274], [-79.924496, 37.224634], [-79.900048, 37.257297], [-79.909493, 37.278054], [-79.879276, 37.304047], [-79.974023, 37.335419], [-80.022226, 37.308338], [-80.033596, 37.324293], [-80.12049, 37.287053], [-80.088062, 37.282334]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "135", "COUNTYNS": "01493928", "GEOID": "51135", "NAME": "Nottoway" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-78.238161, 37.194822], [-78.231234, 37.29622], [-77.795926, 37.192592], [-77.805982, 37.175933], [-77.900254, 37.143885], [-77.889813, 36.988818], [-77.932749, 36.984246], [-77.968114, 36.987292], [-78.003639, 37.022756], [-78.082023, 37.011121], [-78.172207, 37.055963], [-78.170716, 37.076188], [-78.224286, 37.089685], [-78.239354, 37.120089], [-78.238161, 37.194822]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "683", "COUNTYNS": "01498430", "GEOID": "51683", "NAME": "Manassas" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.526457, 38.732466], [-77.475711, 38.781214], [-77.44751, 38.761115], [-77.451642, 38.738337], [-77.471425, 38.728152], [-77.507299, 38.740479], [-77.506167, 38.705741], [-77.526457, 38.732466]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "630", "COUNTYNS": "01498425", "GEOID": "51630", "NAME": "Fredericksburg" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.530283, 38.309175], [-77.506782, 38.325925], [-77.467053, 38.31866], [-77.447126, 38.284614], [-77.457837, 38.271108], [-77.492045, 38.273637], [-77.530283, 38.309175]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "610", "COUNTYNS": "01498423", "GEOID": "51610", "NAME": "Falls Church" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.194712, 38.899073], [-77.172276, 38.893245], [-77.149701, 38.87567], [-77.189719, 38.87801], [-77.194712, 38.899073]]]] } },
]}';
--DECLARE @@CountiesGeoJson nvarchar(max)
--SELECT @@CountiesGeoJson = BulkColumn
--FROM OPENROWSET
--(BULK 'C:\MapData\countiesEdited.json', SINGLE_CLOB)
--as JSON

--Insert Into [Tox].[dbo].[GeoCounties] (GEOID, GEO_NAME, FIPS_ST_CD, FIPS_CNTY_CD, RESOLUTION_ACCURACY, GEO_OBJECT)
select GEOID, GNAME, STATEFP, COUNTYFP, 10, Geo=fixed
from   openjson (@CountiesGeoJson, '$.features')
with
(
    GEOID char(5) '$.properties.GEOID',
    GNAME varchar(40) '$.properties.NAME',
    STATEFP char(2) '$.properties.STATEFP',
    COUNTYFP char(3) '$.properties.COUNTYFP',
    [type] Varchar(64) '$.geometry.type',
    [coordinates] nvarchar(max) '$.geometry.coordinates' as json
)
as GeoData
OUTER APPLY (
select
   stuff(
      (
        select concat(',  ', json_value(Value,'$[0]'),' ',json_value(Value,'$[1]'))
        from openjson(GeoData.coordinates,'$[0]')
        order by cast([key] as int)
        for xml path('')
      ),1,3,'') [path]
      WHERE GeoData.[type] = 'Polygon'
) PolygonData
OUTER APPLY (
    SELECT  STUFF(
        (
            SELECT CONCAT(',  ', polygon)
            FROM OPENJSON(GeoData.coordinates) as Poly
            CROSS APPLY OPENJSON(Poly.value) as Shape
            CROSS APPLY (
                SELECT '(' + stuff(
                (
                    select concat(',  ', json_value(Value,'$[0]'),' ',json_value(Value,'$[1]'))
                    from OPENJSON(Shape.value)
                    order by cast([key] as int)
                    for xml path('')
                ),1,3,'')+')' polygon
        ) Polygons
        for xml path('')
    ),1,3,'') multi
    WHERE GeoData.[type] = 'MultiPolygon'
) MultigonData
cross apply (
    SELECT concat(upper(GeoData.[type]),'((',COALESCE(PolygonData.path, MultigonData.multi),'))') WKT
) shapeDef
-- Extract the SRID from the feature collection header.
outer apply (
    select ID = Substring(name, CharIndex('::', name) + 2, LEN(name) - CharIndex('::', name)) from  openjson (@CountiesGeoJson, '$.crs.properties')
    with ( name varchar(100) '$.name')
) SRID
outer apply (
    select geography::STGeomFromText(WKT,IsNull(SRID.ID, 4326)).MakeValid()/*.ReorientObject()*/ as geom
) geography
outer apply (
    select CASE WHEN geom.EnvelopeAngle() > 90 THEN geom.ReorientObject() ELSE geom END as fixed
) fixes
</code>```

UPDATE: The feature collection header has been modified to match OP.

  SRID now comes from the feature collection header and is not hard coded

ContentLicense: CC BY-SA 4.0

Body:
I am trying to run a query (which I gleened from here) against GeoJson multipolygon data. It processes many of the spatial records but is stopping on a some.

I get the following error in the query messages:

Msg 6522, Level 16, State 1, Line 10

      A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":

      System.FormatException: 24142: Expected "(" at position 15. The input has ",".

      System.FormatException:

      at Microsoft.SqlServer.Types.WellKnownTextReader.RecognizeToken(Char token)     at Microsoft.SqlServer.Types.WellKnownTextReader.ParseLineStringText()

      at Microsoft.SqlServer.Types.WellKnownTextReader.ParsePolygonText()

      at Microsoft.SqlServer.Types.WellKnownTextReader.ParseMultiPolygonText()

      at Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type)

      at Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid)

      at Microsoft.SqlServer.Types.SqlGeography.ParseText(OpenGisType type, SqlChars taggedText, Int32 srid)

      at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)

This is my statement with some test data:

declare @CountiesGeoJson nvarchar(max) = '{"type":"FeatureCollection","features":[
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "700", "COUNTYNS": "01498555", "GEOID": "51700", "NAME": "Newport News" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-76.622252, 37.142146], [-76.577819, 37.187025], [-76.591432, 37.214721], [-76.565092, 37.220645], [-76.458516, 37.100661], [-76.435519, 37.094882], [-76.451274, 37.076878], [-76.442269, 37.018448], [-76.424757, 37.025107], [-76.387711304409194, 36.989671332859004], [-76.411768, 36.962847], [-76.428869, 36.969947], [-76.464471, 37.027547], [-76.518242, 37.055351], [-76.536875, 37.083942], [-76.564219, 37.077507], [-76.618252, 37.119347], [-76.622252, 37.142146]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "620", "COUNTYNS": "01498424", "GEOID": "51620", "NAME": "Franklin" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-76.963021, 36.704696], [-76.912221, 36.698408], [-76.909672, 36.648175], [-76.962339, 36.667515], [-76.949327, 36.67873], [-76.968027, 36.682971], [-76.963021, 36.704696]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "595", "COUNTYNS": "01498422", "GEOID": "51595", "NAME": "Emporia" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.557359, 36.713166], [-77.510273, 36.718229], [-77.509246, 36.682998], [-77.556524, 36.674874], [-77.557359, 36.713166]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "670", "COUNTYNS": "01498428", "GEOID": "51670", "NAME": "Hopewell" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.334549, 37.312468], [-77.273379, 37.316116], [-77.253234, 37.295668], [-77.31081, 37.261451], [-77.328291, 37.271748], [-77.334549, 37.312468]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "510", "COUNTYNS": "01498415", "GEOID": "51510", "NAME": "Alexandria" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.140872, 38.826905], [-77.110799, 38.843446], [-77.087805, 38.827357], [-77.085609, 38.84419], [-77.044487611898006, 38.839598699716696], [-77.040372554526996, 38.785355394851003], [-77.143135, 38.805321], [-77.140872, 38.826905]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "059", "COUNTYNS": "01480119", "GEOID": "51059", "NAME": "Fairfax" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.53576, 38.847474], [-77.32828109319901, 39.057794871536501], [-77.246003, 39.024909], [-77.255703, 39.002409], [-77.234803, 38.97631], [-77.148179, 38.965002], [-77.119759, 38.934343], [-77.172276, 38.893245], [-77.194712, 38.899073], [-77.194234, 38.886146], [-77.149701, 38.87567], [-77.110799, 38.843446], [-77.140872, 38.826905], [-77.143135, 38.805321], [-77.040372554526996, 38.785355394851003], [-77.042298, 38.718515], [-77.122001, 38.685816], [-77.1302, 38.635017], [-77.204302, 38.617817], [-77.277032, 38.695026], [-77.355884, 38.725425], [-77.370878, 38.710433], [-77.442956, 38.803796], [-77.492801, 38.797821], [-77.50834, 38.841032], [-77.53576, 38.847474]], [[-77.334852, 38.853737], [-77.318689, 38.834651], [-77.27052, 38.840902], [-77.270597, 38.866075], [-77.334852, 38.853737]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "680", "COUNTYNS": "01498429", "GEOID": "51680", "NAME": "Lynchburg" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-79.26745, 37.44744], [-79.183302, 37.465908], [-79.120451, 37.398311], [-79.085244, 37.394743], [-79.214924, 37.33258], [-79.257188, 37.355608], [-79.231933, 37.394911], [-79.256628, 37.406573], [-79.244548, 37.419941], [-79.268727, 37.431028], [-79.26745, 37.44744]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "037", "COUNTYNS": "01492442", "GEOID": "51037", "NAME": "Charlotte" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-78.902227, 37.026799], [-78.824209, 37.205361], [-78.808198, 37.201852], [-78.778353, 37.228639], [-78.734351, 37.220256], [-78.681477, 37.24969], [-78.692432, 37.203673], [-78.644621, 37.194323], [-78.634927, 37.170064], [-78.583642, 37.140635], [-78.547128, 37.150431], [-78.480891, 37.085196], [-78.443644, 37.079371], [-78.493028, 36.89122], [-78.648541, 36.697909], [-78.691328, 36.741847], [-78.666145, 36.764363], [-78.682652, 36.797222], [-78.666995, 36.811822], [-78.686878, 36.824331], [-78.666125, 36.840482], [-78.671463, 36.857951], [-78.749727, 36.920065], [-78.727686, 36.937454], [-78.743891, 37.005439], [-78.756549, 37.00717], [-78.748358, 36.987057], [-78.774715, 36.980976], [-78.785452, 36.952783], [-78.817455, 36.98402], [-78.892702, 36.976694], [-78.902227, 37.026799]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "099", "COUNTYNS": "01480137", "GEOID": "51099", "NAME": "King George" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.330384, 38.334951], [-77.286201505089011, 38.347024428844499], [-77.240072, 38.331598], [-77.17934, 38.341915], [-77.138224, 38.367917], [-77.08481, 38.368297], [-77.043526, 38.400548], [-77.011827, 38.374554], [-77.030683, 38.311623], [-76.99767, 38.278047], [-77.044799, 38.260407], [-77.048482, 38.182444], [-77.073796, 38.141331], [-77.084596, 38.160231], [-77.115997, 38.149931], [-77.2143, 38.197029], [-77.254001, 38.18943], [-77.242001, 38.210729], [-77.251801, 38.229628], [-77.229757, 38.245208], [-77.275302, 38.247528], [-77.291402, 38.223729], [-77.290302, 38.238728], [-77.309419, 38.234737], [-77.345728, 38.26139], [-77.330384, 38.334951]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "161", "COUNTYNS": "01480165", "GEOID": "51161", "NAME": "Roanoke" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-80.261984, 37.340694], [-80.200161, 37.378568], [-80.147625, 37.382342], [-80.073985, 37.422305], [-79.865099, 37.328417], [-79.840367, 37.302681], [-79.858058, 37.267138], [-79.847082, 37.225468], [-79.962301, 37.137099], [-80.030562, 37.17481], [-80.088553, 37.160482], [-80.128119, 37.122912], [-80.172264, 37.108156], [-80.189835, 37.233476], [-80.25852, 37.308344], [-80.261984, 37.340694]], [[-80.088062, 37.282334], [-80.050761, 37.252635], [-80.033464, 37.26289], [-80.02883, 37.24365], [-79.998113, 37.252193], [-79.950384, 37.211274], [-79.924496, 37.224634], [-79.900048, 37.257297], [-79.909493, 37.278054], [-79.879276, 37.304047], [-79.974023, 37.335419], [-80.022226, 37.308338], [-80.033596, 37.324293], [-80.12049, 37.287053], [-80.088062, 37.282334]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "135", "COUNTYNS": "01493928", "GEOID": "51135", "NAME": "Nottoway" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-78.238161, 37.194822], [-78.231234, 37.29622], [-77.795926, 37.192592], [-77.805982, 37.175933], [-77.900254, 37.143885], [-77.889813, 36.988818], [-77.932749, 36.984246], [-77.968114, 36.987292], [-78.003639, 37.022756], [-78.082023, 37.011121], [-78.172207, 37.055963], [-78.170716, 37.076188], [-78.224286, 37.089685], [-78.239354, 37.120089], [-78.238161, 37.194822]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "683", "COUNTYNS": "01498430", "GEOID": "51683", "NAME": "Manassas" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.526457, 38.732466], [-77.475711, 38.781214], [-77.44751, 38.761115], [-77.451642, 38.738337], [-77.471425, 38.728152], [-77.507299, 38.740479], [-77.506167, 38.705741], [-77.526457, 38.732466]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "630", "COUNTYNS": "01498425", "GEOID": "51630", "NAME": "Fredericksburg" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.530283, 38.309175], [-77.506782, 38.325925], [-77.467053, 38.31866], [-77.447126, 38.284614], [-77.457837, 38.271108], [-77.492045, 38.273637], [-77.530283, 38.309175]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "610", "COUNTYNS": "01498423", "GEOID": "51610", "NAME": "Falls Church" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.194712, 38.899073], [-77.172276, 38.893245], [-77.149701, 38.87567], [-77.189719, 38.87801], [-77.194712, 38.899073]]]] } },
]}';
--DECLARE @@CountiesGeoJson nvarchar(max)
--SELECT @@CountiesGeoJson = BulkColumn
--FROM OPENROWSET
--(BULK 'C:\MapData\countiesEdited.json', SINGLE_CLOB)
--as JSON

--Insert Into [Tox].[dbo].[GeoCounties] (GEOID, GEO_NAME, FIPS_ST_CD, FIPS_CNTY_CD, RESOLUTION_ACCURACY, GEO_OBJECT)
select GEOID, GNAME, STATEFP, COUNTYFP, 10, Geo=fixed
from   openjson (@CountiesGeoJson, '$.features')
with
(
    GEOID char(5) '$.properties.GEOID',
    GNAME varchar(40) '$.properties.NAME',
    STATEFP char(2) '$.properties.STATEFP',
    COUNTYFP char(3) '$.properties.COUNTYFP',
    [type] Varchar(64) '$.geometry.type',
    [coordinates] nvarchar(max) '$.geometry.coordinates' as json
)
as GeoData
cross apply (
select
   stuff(
      (
        select concat(',  ', json_value(Value,'$[0]'),' ',json_value(Value,'$[1]'))
        from openjson(GeoData.coordinates,'$[0]')
        order by cast([key] as int)
        for xml path('')
      ),1,3,'') [path]
) PolygonData
OUTER APPLY (
    SELECT  STUFF(
        (
            SELECT CONCAT(',  ', polygon)
            FROM OPENJSON(GeoData.coordinates) as Poly
            CROSS APPLY OPENJSON(Poly.value) as Shape
            CROSS APPLY (
                SELECT '(' + stuff(
                (
                    select concat(',  ', json_value(Value,'$[0]'),' ',json_value(Value,'$[1]'))
                    from OPENJSON(Shape.value)
                    order by cast([key] as int)
                    for xml path('')
                ),1,3,'')+')' polygon
        ) Polygons
        for xml path('')
    ),1,3,'') multi
    WHERE LEN(Path) = 0
) MultigonData
cross apply (
    SELECT concat(upper(GeoData.[type]),'((',IsNull(NULLIF(path,''),multi),'))') WKT
) shapeDef
outer apply (
    select geography::STGeomFromText(WKT,4326).MakeValid()/*.ReorientObject()*/ as geom
) geography
outer apply (
    select CASE WHEN geom.EnvelopeAngle() > 90 THEN geom.ReorientObject() ELSE geom END as fixed
) fixes

The query will run and produce some results but when it hits records where the NAME = 'Fairfax' and 'Roanoke', it stops with the above error.

Can anyone see the issue and know how to resolve this?

[EDIT 2019-05-31 17:35]
GeoJson Header:

{
  "type": "FeatureCollection",
  "name": "USCounty_Simplify_01",
  "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::4269" } },
  "features": [
...

Body:
Thanks @Hank for taking this query for a spin! @Vitaly-Borisov has highlighted the specific offending geometry, this has helped immensely in solving the issue.

In the original Query, there is a CROSS APPLY query that creates a result set called PolygonData, immediately after that is an OUTER APLY that creates a result set called MultigonData.

Notice that MultigonData only has results WHERE LEN(Path) = 0

The expectation here was that all non polygon geometry would yield a null value for Path and so we only attempt to resolve the MultiPolygon WKT if the geometry was indeed a MultiPolygon type.

This query only supports Polygon and MultiPolygon types of geometry, it was a broad enough assumption that suited at that time.

Instead of using the failure to resolve a Polygon (WHERE LEN(Path) = 0) to determine that the geometry is in fact a MultiPolygon, we can use the type definition itself!

Updated Query, notice the where clauses within the PolygonData and MutigonData queries and the use of COALESCE in shapeDef

These minor changes should make it easier to adopt this logic for other geography types.

declare @CountiesGeoJson nvarchar(max) = '{ "type": "FeatureCollection", "name": "USCounty_Simplify_01", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::4269" } }, "features": [
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "700", "COUNTYNS": "01498555", "GEOID": "51700", "NAME": "Newport News" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-76.622252, 37.142146], [-76.577819, 37.187025], [-76.591432, 37.214721], [-76.565092, 37.220645], [-76.458516, 37.100661], [-76.435519, 37.094882], [-76.451274, 37.076878], [-76.442269, 37.018448], [-76.424757, 37.025107], [-76.387711304409194, 36.989671332859004], [-76.411768, 36.962847], [-76.428869, 36.969947], [-76.464471, 37.027547], [-76.518242, 37.055351], [-76.536875, 37.083942], [-76.564219, 37.077507], [-76.618252, 37.119347], [-76.622252, 37.142146]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "620", "COUNTYNS": "01498424", "GEOID": "51620", "NAME": "Franklin" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-76.963021, 36.704696], [-76.912221, 36.698408], [-76.909672, 36.648175], [-76.962339, 36.667515], [-76.949327, 36.67873], [-76.968027, 36.682971], [-76.963021, 36.704696]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "595", "COUNTYNS": "01498422", "GEOID": "51595", "NAME": "Emporia" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.557359, 36.713166], [-77.510273, 36.718229], [-77.509246, 36.682998], [-77.556524, 36.674874], [-77.557359, 36.713166]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "670", "COUNTYNS": "01498428", "GEOID": "51670", "NAME": "Hopewell" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.334549, 37.312468], [-77.273379, 37.316116], [-77.253234, 37.295668], [-77.31081, 37.261451], [-77.328291, 37.271748], [-77.334549, 37.312468]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "510", "COUNTYNS": "01498415", "GEOID": "51510", "NAME": "Alexandria" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.140872, 38.826905], [-77.110799, 38.843446], [-77.087805, 38.827357], [-77.085609, 38.84419], [-77.044487611898006, 38.839598699716696], [-77.040372554526996, 38.785355394851003], [-77.143135, 38.805321], [-77.140872, 38.826905]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "059", "COUNTYNS": "01480119", "GEOID": "51059", "NAME": "Fairfax" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.53576, 38.847474], [-77.32828109319901, 39.057794871536501], [-77.246003, 39.024909], [-77.255703, 39.002409], [-77.234803, 38.97631], [-77.148179, 38.965002], [-77.119759, 38.934343], [-77.172276, 38.893245], [-77.194712, 38.899073], [-77.194234, 38.886146], [-77.149701, 38.87567], [-77.110799, 38.843446], [-77.140872, 38.826905], [-77.143135, 38.805321], [-77.040372554526996, 38.785355394851003], [-77.042298, 38.718515], [-77.122001, 38.685816], [-77.1302, 38.635017], [-77.204302, 38.617817], [-77.277032, 38.695026], [-77.355884, 38.725425], [-77.370878, 38.710433], [-77.442956, 38.803796], [-77.492801, 38.797821], [-77.50834, 38.841032], [-77.53576, 38.847474]], [[-77.334852, 38.853737], [-77.318689, 38.834651], [-77.27052, 38.840902], [-77.270597, 38.866075], [-77.334852, 38.853737]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "680", "COUNTYNS": "01498429", "GEOID": "51680", "NAME": "Lynchburg" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-79.26745, 37.44744], [-79.183302, 37.465908], [-79.120451, 37.398311], [-79.085244, 37.394743], [-79.214924, 37.33258], [-79.257188, 37.355608], [-79.231933, 37.394911], [-79.256628, 37.406573], [-79.244548, 37.419941], [-79.268727, 37.431028], [-79.26745, 37.44744]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "037", "COUNTYNS": "01492442", "GEOID": "51037", "NAME": "Charlotte" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-78.902227, 37.026799], [-78.824209, 37.205361], [-78.808198, 37.201852], [-78.778353, 37.228639], [-78.734351, 37.220256], [-78.681477, 37.24969], [-78.692432, 37.203673], [-78.644621, 37.194323], [-78.634927, 37.170064], [-78.583642, 37.140635], [-78.547128, 37.150431], [-78.480891, 37.085196], [-78.443644, 37.079371], [-78.493028, 36.89122], [-78.648541, 36.697909], [-78.691328, 36.741847], [-78.666145, 36.764363], [-78.682652, 36.797222], [-78.666995, 36.811822], [-78.686878, 36.824331], [-78.666125, 36.840482], [-78.671463, 36.857951], [-78.749727, 36.920065], [-78.727686, 36.937454], [-78.743891, 37.005439], [-78.756549, 37.00717], [-78.748358, 36.987057], [-78.774715, 36.980976], [-78.785452, 36.952783], [-78.817455, 36.98402], [-78.892702, 36.976694], [-78.902227, 37.026799]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "099", "COUNTYNS": "01480137", "GEOID": "51099", "NAME": "King George" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.330384, 38.334951], [-77.286201505089011, 38.347024428844499], [-77.240072, 38.331598], [-77.17934, 38.341915], [-77.138224, 38.367917], [-77.08481, 38.368297], [-77.043526, 38.400548], [-77.011827, 38.374554], [-77.030683, 38.311623], [-76.99767, 38.278047], [-77.044799, 38.260407], [-77.048482, 38.182444], [-77.073796, 38.141331], [-77.084596, 38.160231], [-77.115997, 38.149931], [-77.2143, 38.197029], [-77.254001, 38.18943], [-77.242001, 38.210729], [-77.251801, 38.229628], [-77.229757, 38.245208], [-77.275302, 38.247528], [-77.291402, 38.223729], [-77.290302, 38.238728], [-77.309419, 38.234737], [-77.345728, 38.26139], [-77.330384, 38.334951]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "161", "COUNTYNS": "01480165", "GEOID": "51161", "NAME": "Roanoke" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-80.261984, 37.340694], [-80.200161, 37.378568], [-80.147625, 37.382342], [-80.073985, 37.422305], [-79.865099, 37.328417], [-79.840367, 37.302681], [-79.858058, 37.267138], [-79.847082, 37.225468], [-79.962301, 37.137099], [-80.030562, 37.17481], [-80.088553, 37.160482], [-80.128119, 37.122912], [-80.172264, 37.108156], [-80.189835, 37.233476], [-80.25852, 37.308344], [-80.261984, 37.340694]], [[-80.088062, 37.282334], [-80.050761, 37.252635], [-80.033464, 37.26289], [-80.02883, 37.24365], [-79.998113, 37.252193], [-79.950384, 37.211274], [-79.924496, 37.224634], [-79.900048, 37.257297], [-79.909493, 37.278054], [-79.879276, 37.304047], [-79.974023, 37.335419], [-80.022226, 37.308338], [-80.033596, 37.324293], [-80.12049, 37.287053], [-80.088062, 37.282334]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "135", "COUNTYNS": "01493928", "GEOID": "51135", "NAME": "Nottoway" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-78.238161, 37.194822], [-78.231234, 37.29622], [-77.795926, 37.192592], [-77.805982, 37.175933], [-77.900254, 37.143885], [-77.889813, 36.988818], [-77.932749, 36.984246], [-77.968114, 36.987292], [-78.003639, 37.022756], [-78.082023, 37.011121], [-78.172207, 37.055963], [-78.170716, 37.076188], [-78.224286, 37.089685], [-78.239354, 37.120089], [-78.238161, 37.194822]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "683", "COUNTYNS": "01498430", "GEOID": "51683", "NAME": "Manassas" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.526457, 38.732466], [-77.475711, 38.781214], [-77.44751, 38.761115], [-77.451642, 38.738337], [-77.471425, 38.728152], [-77.507299, 38.740479], [-77.506167, 38.705741], [-77.526457, 38.732466]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "630", "COUNTYNS": "01498425", "GEOID": "51630", "NAME": "Fredericksburg" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.530283, 38.309175], [-77.506782, 38.325925], [-77.467053, 38.31866], [-77.447126, 38.284614], [-77.457837, 38.271108], [-77.492045, 38.273637], [-77.530283, 38.309175]]]] } },
{ "type": "Feature", "properties": { "STATEFP": "51", "COUNTYFP": "610", "COUNTYNS": "01498423", "GEOID": "51610", "NAME": "Falls Church" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-77.194712, 38.899073], [-77.172276, 38.893245], [-77.149701, 38.87567], [-77.189719, 38.87801], [-77.194712, 38.899073]]]] } },
]}';
--DECLARE @@CountiesGeoJson nvarchar(max)
--SELECT @@CountiesGeoJson = BulkColumn
--FROM OPENROWSET
--(BULK 'C:\MapData\countiesEdited.json', SINGLE_CLOB)
--as JSON

--Insert Into [Tox].[dbo].[GeoCounties] (GEOID, GEO_NAME, FIPS_ST_CD, FIPS_CNTY_CD, RESOLUTION_ACCURACY, GEO_OBJECT)
select GEOID, GNAME, STATEFP, COUNTYFP, 10, Geo=fixed
from   openjson (@CountiesGeoJson, '$.features')
with
(
    GEOID char(5) '$.properties.GEOID',
    GNAME varchar(40) '$.properties.NAME',
    STATEFP char(2) '$.properties.STATEFP',
    COUNTYFP char(3) '$.properties.COUNTYFP',
    [type] Varchar(64) '$.geometry.type',
    [coordinates] nvarchar(max) '$.geometry.coordinates' as json
)
as GeoData
OUTER APPLY (
select
   stuff(
      (
        select concat(',  ', json_value(Value,'$[0]'),' ',json_value(Value,'$[1]'))
        from openjson(GeoData.coordinates,'$[0]')
        order by cast([key] as int)
        for xml path('')
      ),1,3,'') [path]
      WHERE GeoData.[type] = 'Polygon'
) PolygonData
OUTER APPLY (
    SELECT  STUFF(
        (
            SELECT CONCAT(',  ', polygon)
            FROM OPENJSON(GeoData.coordinates) as Poly
            CROSS APPLY OPENJSON(Poly.value) as Shape
            CROSS APPLY (
                SELECT '(' + stuff(
                (
                    select concat(',  ', json_value(Value,'$[0]'),' ',json_value(Value,'$[1]'))
                    from OPENJSON(Shape.value)
                    order by cast([key] as int)
                    for xml path('')
                ),1,3,'')+')' polygon
        ) Polygons
        for xml path('')
    ),1,3,'') multi
    WHERE GeoData.[type] = 'MultiPolygon'
) MultigonData
cross apply (
    SELECT concat(upper(GeoData.[type]),'((',COALESCE(PolygonData.path, MultigonData.multi),'))') WKT
) shapeDef
-- Extract the SRID from the feature collection header.
outer apply (
    select ID = Substring(name, CharIndex('::', name) + 2, LEN(name) - CharIndex('::', name)) from  openjson (@CountiesGeoJson, '$.crs.properties')
    with ( name varchar(100) '$.name')
) SRID
outer apply (
    select geography::STGeomFromText(WKT,IsNull(SRID.ID, 4326)).MakeValid()/*.ReorientObject()*/ as geom
) geography
outer apply (
    select CASE WHEN geom.EnvelopeAngle() > 90 THEN geom.ReorientObject() ELSE geom END as fixed
) fixes

UPDATE: The feature collection header has been modified to match OP.

  SRID now comes from the feature collection header and is not hard coded


问:
How to print first 5 rows of all the tables in an oracle database (schema)?
I want to open a database (schema) which holds about 100 tables,
Once it's opened I would like to print the top 5 rows of all the tables along with their column names.

My first step was to try and get the schema and table names in the database.
so this is what I used for that.

```<code>SELECT owner, table_name
  FROM all_tables
</code>```

The expected result will contain the table name, column names and top 5 rows of the table.

I am using Oracle SQL Developer ( Oracle database)

答:
You can try this if you're running Oracle 12c and above.

```<code>SET SERVEROUTPUT ON
SET FEEDBACK OFF
DECLARE
     x SYS_REFCURSOR;
BEGIN
     FOR tabs IN ( SELECT rownum as rn,owner,table_name
                   FROM all_tables where owner='HR'
                   and ROWNUM < 10
                 ) LOOP

 OPEN x FOR 'SELECT '''|| tabs.owner||'.'|| tabs.table_name||'''
     as "table" FROM DUAL';

 dbms_sql.return_result(x);

          OPEN x FOR 'select * from '
                     || tabs.owner
                     ||'.'
                     || tabs.table_name
                     || ' FETCH FIRST 5 ROWS ONLY ';

          dbms_sql.return_result(x);
     END LOOP;
END;
/
</code>```

Output

```<code>table
----------
HR.REGIONS

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa

table
------------
HR.LOCATIONS

LOCATION_ID STREET_ADDRESS                           POSTAL_CODE  CITY                           STATE_PROVINCE            CO
----------- ---------------------------------------- ------------ ------------------------------ ------------------------- --
       1000 1297 Via Cola di Rie                     00989        Roma                                                     IT
       1100 93091 Calle della Testa                  10934        Venice                                                   IT
       1200 2017 Shinjuku-ku                         1689         Tokyo                          Tokyo Prefecture          JP
       1300 9450 Kamiya-cho                          6823         Hiroshima                                                JP
       1400 2014 Jabberwocky Rd                      26192        Southlake                      Texas                     US

table
--------------
HR.DEPARTMENTS

DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------
           10 Administration                        200        1700
           20 Marketing                             201        1800
           30 Purchasing                            114        1700
           40 Human Resources                       203        2400
           50 Shipping                              121        1500
</code>```

Body:
I want to open a database (schema) which holds about 100 tables,
Once it's opened I would like to print the top 5 rows of all the tables along with their column names.

My first step was to try and get the schema and table names in the database.
so this is what I used for that.

SELECT owner, table_name
  FROM all_tables

The expected result will contain the table name, column names and top 5 rows of the table.

I am using Oracle SQL Developer ( Oracle database)

Body:
You can try this if you're running Oracle 12c and above.

SET SERVEROUTPUT ON
SET FEEDBACK OFF
DECLARE
     x SYS_REFCURSOR;
BEGIN
     FOR tabs IN ( SELECT rownum as rn,owner,table_name
                   FROM all_tables where owner='HR'
                   and ROWNUM < 10
                 ) LOOP

 OPEN x FOR 'SELECT '''|| tabs.owner||'.'|| tabs.table_name||'''
     as "table" FROM DUAL';

 dbms_sql.return_result(x);

          OPEN x FOR 'select * from '
                     || tabs.owner
                     ||'.'
                     || tabs.table_name
                     || ' FETCH FIRST 5 ROWS ONLY ';

          dbms_sql.return_result(x);
     END LOOP;
END;
/

Output

table
----------
HR.REGIONS

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa

table
------------
HR.LOCATIONS

LOCATION_ID STREET_ADDRESS                           POSTAL_CODE  CITY                           STATE_PROVINCE            CO
----------- ---------------------------------------- ------------ ------------------------------ ------------------------- --
       1000 1297 Via Cola di Rie                     00989        Roma                                                     IT
       1100 93091 Calle della Testa                  10934        Venice                                                   IT
       1200 2017 Shinjuku-ku                         1689         Tokyo                          Tokyo Prefecture          JP
       1300 9450 Kamiya-cho                          6823         Hiroshima                                                JP
       1400 2014 Jabberwocky Rd                      26192        Southlake                      Texas                     US

table
--------------
HR.DEPARTMENTS

DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------
           10 Administration                        200        1700
           20 Marketing                             201        1800
           30 Purchasing                            114        1700
           40 Human Resources                       203        2400
           50 Shipping                              121        1500


问:
TypeScript + React: enforce correct ref props
I just got bitten by a runtime exception because I passed a React ref into the wrong component.

I wonder if/how TypeScript could have saved my bacon here?

Reduced test case:

```<code>import * as React from 'react';

class Modal extends React.Component<{}> {
    close = () => {};
}

declare const modal: Modal;

modal.close();

const modalRef = React.createRef<Modal>();

// Let's try giving this ref to the correct component…
// No error as expected :-)
<Modal ref={modalRef} />;

class SomeOtherComponent extends React.Component<{}> {}

// Let's try giving this ref to the wrong component…
// Expected type error but got none! :-(
<SomeOtherComponent ref={modalRef} />;

// Now when we try to use this ref, TypeScript tells us it's safe to do so.
// But it's not, because the ref has been incorrectly assigned to another component!
if (modalRef.current !== null) {
    modalRef.current.close() // runtime error!
}
</code>```

答:
The reason why aren't getting any errors with ref is in the fact that both your components are derivatives of the same base class React.Component in your example, but they don't have any differing properties and don't have an explicit interface.

Check a section on type compatibility in Typescript:
https://www.typescriptlang.org/docs/handbook/type-compatibility.html

As Typescript uses structural instead of nominal subtyping, classes can be merged and compared as equal in the following scenarios:

Both have the same property members

Neither has any property members (not a realistic case, but it is the one that you have)

One class can have members that other one doesn't have, but ONLY if it has all of the properties from the other class. E.g. it can add stuff, but not introduce new things

Constructors can differ

You can also redefine the same property member

In all other cases, they are not compatible.

In case you rewrite to:

React.createRef<HTMLInputElement>();

You will clearly be able to see that refs are outlined as incompatible on your components for example.

This is because React.Component is not in any way compatible with HTMLElement type (which HTMLInputElement is a derivative off e.g. these classses have different properties).

It's not that this assertion doesn't work, it's more of a case of how exactly it works under the hood, which follows the rules outlined on top.

Back to the issue at hand

You can do several things to avoid these kinds of issues, dependant on your situation,

You have 2 components, with differing react props.

In case your components have differing props, create interfaces for both, and you will not have this issue, as it will return a type error that Props on these components don't match which is true.

You have 2 components, with no custom react properties

Your current problem. In case you add a new property member to SomeOtherComponent that doesn't exist in class Modal, for example, open = () =>, then they will be resolved as different.

Summary

In case you can't add an interface, and you don't have differing property members in these 2 classes, then it is realistic enough that this is the same class.

You just need to figure out a better way how to use it for both scenarios.

Body:
I just got bitten by a runtime exception because I passed a React ref into the wrong component.

I wonder if/how TypeScript could have saved my bacon here?

Reduced test case:

import * as React from 'react';

class Modal extends React.Component<{}> {
    close = () => {};
}

declare const modal: Modal;

modal.close();

const modalRef = React.createRef<Modal>();

// Let's try giving this ref to the correct component…
// No error as expected :-)
<Modal ref={modalRef} />;

class SomeOtherComponent extends React.Component<{}> {}

// Let's try giving this ref to the wrong component…
// Expected type error but got none! :-(
<SomeOtherComponent ref={modalRef} />;

// Now when we try to use this ref, TypeScript tells us it's safe to do so.
// But it's not, because the ref has been incorrectly assigned to another component!
if (modalRef.current !== null) {
    modalRef.current.close() // runtime error!
}


问:
How to create a directory in a function
Editing:

I'm trying to build a simple function that print out a name, then creates a directory. I'm new at building function in bash, so I have the below script that didn't work:

```<code>dest_path=/home/all/todo
line="name"

mkdir_for_name() {
echo $1
mkdir $2
}

mkdir_for_name $name
mkdir_for_name $dest_path/$name
</code>```

What is wrong with that syntax?

答:
You defined a function that accepts 2 arguments, where the first argument passed is the name to be printed on screen (the "echo" line), while the second argument passed will create the desidered folder.
Passing only one argument will just print on screen that argument</p>

Title: How to create a directory in a function

Body:
Editing:

I'm trying to build a simple function that print out a name, then creates a directory. I'm new at building function in bash, so I have the below script that didn't work:

dest_path=/home/all/todo
line="name"

mkdir_for_name() {
echo $1
mkdir $2
}

mkdir_for_name $name
mkdir_for_name $dest_path/$name

What is wrong with that syntax?


问:
Converting List<string> to byte[]
How can I take a List and turn it into a byte array.

I thought there might be some clever LINQ options for it but am unsure eg/List.ForEach

答:
Depends on which encoding you want to use to convert the string to a byte[] but here's a sample for ASCII.  It can be substituted for pretty much any encoding type

```<code>List<string> data = ...
byte[] dataAsBytes = data
  .SelectMany(s => Text.Encoding.ASCII.GetBytes(s))
  .ToArray();
</code>```

Title: Converting List<string> to byte[]

Body:
Depends on which encoding you want to use to convert the string to a byte[] but here's a sample for ASCII.  It can be substituted for pretty much any encoding type

List<string> data = ...
byte[] dataAsBytes = data
  .SelectMany(s => Text.Encoding.ASCII.GetBytes(s))
  .ToArray();


问:
finding text between words on multiple lines
In the text below Im trying to identify which family member the text belongs too. The comment will preceded the family member.. So in the sample below I should only identify the Mother.. the father does not have a comment

```<code>some stuf Father
more stuff Mother

Comment: Deceased
</code>```

After searching and trying some negative lookaround I still can't seem to get it to work.. So for example..

```<code>Father(?!Mother).*Comment:\s?(deceased|died)
</code>```

This regex should NOT find a match.. But it ends up matching

```<code>Father
more stuff Mother

Comment: deceased
</code>```

If I switch Mother and Father it matches correctly.. But I need to not match in the example because the comment does not belong to the Father

答:
You have to extend the negative lookahead (?!.*?Mother) to match any character 0+ times or else it would assert what is directly to the right is not Mother.

In this case Mother does not follow directly after Father so the assertion succeeds and this part .*Comment will match until the last occurrence of Comment where what follows can match.

Your pattern could look like:

```<code>Father(?!.*?Mother).*Comment:\s?(deceased|died)
</code>```

Regex demo

Perhaps you might make the dot star approach for the Comment no greedy as well to prevent over matching:

```<code>.*?Comment
</code>```

Body:
In the text below Im trying to identify which family member the text belongs too. The comment will preceded the family member.. So in the sample below I should only identify the Mother.. the father does not have a comment

some stuf Father
more stuff Mother

Comment: Deceased

After searching and trying some negative lookaround I still can't seem to get it to work.. So for example..

Father(?!Mother).*Comment:\s?(deceased|died)

This regex should NOT find a match.. But it ends up matching

Father
more stuff Mother

Comment: deceased

If I switch Mother and Father it matches correctly.. But I need to not match in the example because the comment does not belong to the Father

Body:
You have to extend the negative lookahead (?!.*?Mother) to match any character 0+ times or else it would assert what is directly to the right is not Mother.

In this case Mother does not follow directly after Father so the assertion succeeds and this part .*Comment will match until the last occurrence of Comment where what follows can match.

Your pattern could look like:

Father(?!.*?Mother).*Comment:\s?(deceased|died)

Regex demo

Perhaps you might make the dot star approach for the Comment no greedy as well to prevent over matching:

.*?Comment


问:
JavaScript: how to change CSS style of created span?
```<code>  newNode = document.createElement("span");
  newNode.innerHTML = "text";
  range.insertNode(newNode);
</code>```

Is it possible to make the text in innerHTML with red background color?  I want to add style="background-color:red" to just created span. Is it possible? Or it must have some id, and then I can change this span with jQuery?

答:
You can add attributes directly to the DOM object. The style attribute can be assigned by this way too. Example:

```<code>var span = document.createElement("span");
span.setAttribute("style","color:white;background-color:red;");

var text = document.createTextNode("My text");
span.appendChild(text);
</code>```

Of course you have to add this element created to their parent object in your page:

```<code>var parent = document.getElementById("parentObject");
parent.appendChild(span);
</code>```

This method "setAttribute()" lets you to add other non-standard attributes used by animations and custom jquery options to your HTML standard tags.

Body:
  newNode = document.createElement("span");
  newNode.innerHTML = "text";
  range.insertNode(newNode);

Is it possible to make the text in innerHTML with red background color?  I want to add style="background-color:red" to just created span. Is it possible? Or it must have some id, and then I can change this span with jQuery?

Body:
You can add attributes directly to the DOM object. The style attribute can be assigned by this way too. Example:

var span = document.createElement("span");
span.setAttribute("style","color:white;background-color:red;");

var text = document.createTextNode("My text");
span.appendChild(text);

Of course you have to add this element created to their parent object in your page:

var parent = document.getElementById("parentObject");
parent.appendChild(span);

This method "setAttribute()" lets you to add other non-standard attributes used by animations and custom jquery options to your HTML standard tags.


问:
Dynamically add icon name with Ionic2
I'm trying to dynamically add icon names to my Ionic 2 app, the reason for this is that I have a list of attributes on my model, which are dynamic, the model returns the icon name to the ionic 2 application.

This is the response I'm getting from my API.

```<code>{
  "type": "searchresult",
  "count": 1,
  "results": [
    {
      "type": "room",
      "url": "/api/room/1",
      "id": 1,
      "name": "name1",
      "attributes": [
        {
          "type": "attribute",
          "url": "/api/room/1/attribute/1",
          "name": "attribute1",
          "icon": "people",
          "valueType": "bool",
          "value": "true"
        },
        {
          "type": "attribute",
          "url": "/api/room/1/attribute/3",
          "name": "attribute2",
          "icon": "desktop",
          "valueType": "bool",
          "value": "true"
        },
        {
          "type": "attribute",
          "url": "/api/room/1/attribute/4",
          "name": "attribute3",
          "icon": "md-videocam",
          "valueType": "bool",
          "value": "true"
        },
        {
          "type": "attribute",
          "url": "/api/room/1/attribute/5",
          "name": "attribute4",
          "icon": "icon-chair",
          "valueType": "int",
          "value": "200"
        }
      ]
    }
  }
</code>```

This is what I have in the Ionic2 app at the moment.

```<code><ion-row no-padding *ngFor="let att of room.attributes">
    <ion-col width-20 no-padding text-center>
        <ion-icon name="att.icon"</ion-icon>
    </ion-col>
</ion-row>
</code>```

Thank you in advance.

答:
When data has come from ngFor I've had to use this before :

[attr.name]="ngForItem.name"

(using your code) :

```<code><ion-row no-padding *ngFor="let att of room.attributes">
    <ion-col width-20 no-padding text-center>
        <ion-icon [attr.name]="att.icon"</ion-icon>
    </ion-col>
</ion-row>
</code>```

Title: Dynamically add icon name with Ionic2

Body:
I'm trying to dynamically add icon names to my Ionic 2 app, the reason for this is that I have a list of attributes on my model, which are dynamic, the model returns the icon name to the ionic 2 application.

This is the response I'm getting from my API.

{
  "type": "searchresult",
  "count": 1,
  "results": [
    {
      "type": "room",
      "url": "/api/room/1",
      "id": 1,
      "name": "name1",
      "attributes": [
        {
          "type": "attribute",
          "url": "/api/room/1/attribute/1",
          "name": "attribute1",
          "icon": "people",
          "valueType": "bool",
          "value": "true"
        },
        {
          "type": "attribute",
          "url": "/api/room/1/attribute/3",
          "name": "attribute2",
          "icon": "desktop",
          "valueType": "bool",
          "value": "true"
        },
        {
          "type": "attribute",
          "url": "/api/room/1/attribute/4",
          "name": "attribute3",
          "icon": "md-videocam",
          "valueType": "bool",
          "value": "true"
        },
        {
          "type": "attribute",
          "url": "/api/room/1/attribute/5",
          "name": "attribute4",
          "icon": "icon-chair",
          "valueType": "int",
          "value": "200"
        }
      ]
    }
  }

This is what I have in the Ionic2 app at the moment.

<ion-row no-padding *ngFor="let att of room.attributes">
    <ion-col width-20 no-padding text-center>
        <ion-icon name="att.icon"</ion-icon>
    </ion-col>
</ion-row>

Thank you in advance.

Body:
When data has come from ngFor I've had to use this before :

[attr.name]="ngForItem.name"

(using your code) :

<ion-row no-padding *ngFor="let att of room.attributes">
    <ion-col width-20 no-padding text-center>
        <ion-icon [attr.name]="att.icon"</ion-icon>
    </ion-col>
</ion-row>


问:
How to select drop-down value in Protractor using framework: 'jasmine',
I am trying to select drop down list using protractor. None of this code works.

```<code>it("Select Block from District", function() {

    const selectElement={}
    selectElement.selectElementDropdown =function(element,index,milliseconds){
     console.log("Selecting element by drop down","OK");

     element.all(by.tagName('option')).then(function(options){

         options[2].click();
    //here index 2 is hardcoded, which can be changed to options[index]
     });

     if(typeof milliseconds!=='undefined'){
         browser.sleep(milliseconds);
     }

    }

    module.exports =selectElement;

    const methodDropDown = {} //require('../Src/SelectElement.js');

    var DistrictDetails = function(){

    this.DistrictName = element.all(by.xpath("//label[text()='Select Block']")).get(7).element(by.xpath("//option[contains(text(),'Ambabhona')]"));
    //the selector is clicked to open the drop down
</code>```

I have already gone through pass the value using send keys to text box

```<code><div _ngcontent-c9="" class="col-sm-6">
    <label _ngcontent-c9="" class="col-md-5 control-label">District
        <span _ngcontent-c9="" class="err-msg">*</span>
    </label>
    <div _ngcontent-c9="" class="col-md-7">
        <p-dropdown _ngcontent-c9="" formcontrolname="districtId" placeholder="Select District"
            class="ng-tns-c6-189 ng-pristine ng-invalid ng-touched">
            <div class="ng-tns-c6-189 ui-dropdown ui-widget ui-state-default ui-corner-all ui-helper-clearfix"
                style="width: 138px;">
                <!---->
                <div class="ui-helper-hidden-accessible ng-tns-c6-189 ng-star-inserted">
                    <select class="ng-tns-c6-189" aria-hidden="true" tabindex="-1" aria-label=" ">
                        <!---->
                        <option class="ng-tns-c6-189 ng-star-inserted">Select District</option>
                        <!---->
                        <!---->
                        <!---->
                        <!---->
                        <option class="ng-tns-c6-189 ng-star-inserted" value="390" style="">Bargarh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="391" style="">Jharsuguda</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="392" style="">Sambalpur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="393" style="">Deogarh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="394" style="">Sundergarh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="395" style="">Keonjhar</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="396" style="">Mayurbhanj</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="397" style="">Balasore</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="398" style="">Bhadrak</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="399" style="">Kendrapara</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="400" style="">Jagatsinghpur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="401" style="">Cuttack</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="402" style="">Jajpur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="403" style="">Dhenkanal</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="404" style="">Angul</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="405" style="">Nayagarh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="406" style="">Khordha</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="407" style="">Puri</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="408" style="">Ganjam</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="409" style="">Gajapati</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="410" style="">Kandhamal</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="411" style="">Boudh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="412" style="">Sonepur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="413" style="">Bolangir</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="414" style="">Nuapada</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="415" style="">Kalahandi</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="416" style="">Rayagada</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="417" style="">Nabarangpur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="418" style="">Koraput</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="419" style="">Malkangiri</option>
                        <!---->
                    </select>
                </div>
                <div class="ui-helper-hidden-accessible">
                    <input class="ng-tns-c6-189" readonly="" role="listbox" type="text" aria-label=" ">
                </div>
                <!---->
                <!----><label
                    class="ng-tns-c6-189 ui-dropdown-label ui-inputtext ui-corner-all ui-placeholder ng-star-inserted">
                    Select District
                </label>
                <!---->
                <!---->
                <div class="ui-dropdown-trigger ui-state-default ui-corner-right"><span
                        class="ui-dropdown-trigger-icon ui-clickable pi pi-caret-down"></span>
                </div>
                <div class="ng-tns-c6-189 ui-dropdown-panel ui-widget-content ui-corner-all ui-shadow ng-trigger ng-trigger-panelState"
                    style="display: none; z-index: 1181; top: 27px; left: 0px; opacity: 0;">
                    <!---->
                    <div class="ui-dropdown-items-wrapper" style="max-height: 200px;">
                        <!---->
                    </div>
                </div>
            </div>
        </p-dropdown>
        <!---->
    </div>
</div>
</code>```

Want to select value form drop-down list like  Deogarh

答:
usually either of described approached work. Note I'm using async/await in my code

1. Easy way

Declare js click (inject script in console). and then just click any option directly

```<code>let jsClick = ($element) => browser.executeScript(
    "arguments[0].click();",
    $element.getWebElement()
);

let $option = $("option[value='395']");

await jsClick($option);
</code>```

This injected click works differently then protractor .click(). It may click elements even if they are mot visible. Works, but not really UI verification

2. What user would do

Requires scrolling

```<code>let scroll = ($element, offsetY = 0) => browser.executeScript(
        `arguments[0].scrollIntoView();
        window.scroll(
            0,window.scrollY-50-(${offsetY})
        );`,
        $element.getWebElement()
     );

await $visibleDropdown.click();
await scroll($yourOption);
await $yourOption.click();
</code>```

Let me know if neither helped

Body:
I am trying to select drop down list using protractor. None of this code works.

it("Select Block from District", function() {

    const selectElement={}
    selectElement.selectElementDropdown =function(element,index,milliseconds){
     console.log("Selecting element by drop down","OK");

     element.all(by.tagName('option')).then(function(options){

         options[2].click();
    //here index 2 is hardcoded, which can be changed to options[index]
     });

     if(typeof milliseconds!=='undefined'){
         browser.sleep(milliseconds);
     }

    }

    module.exports =selectElement;

    const methodDropDown = {} //require('../Src/SelectElement.js');

    var DistrictDetails = function(){

    this.DistrictName = element.all(by.xpath("//label[text()='Select Block']")).get(7).element(by.xpath("//option[contains(text(),'Ambabhona')]"));
    //the selector is clicked to open the drop down

I have already gone through pass the value using send keys to text box

    District
        *

                    <select class="ng-tns-c6-189" aria-hidden="true" tabindex="-1" aria-label=" ">

                        <option class="ng-tns-c6-189 ng-star-inserted">Select District</option>

                        <option class="ng-tns-c6-189 ng-star-inserted" value="390" style="">Bargarh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="391" style="">Jharsuguda</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="392" style="">Sambalpur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="393" style="">Deogarh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="394" style="">Sundergarh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="395" style="">Keonjhar</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="396" style="">Mayurbhanj</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="397" style="">Balasore</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="398" style="">Bhadrak</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="399" style="">Kendrapara</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="400" style="">Jagatsinghpur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="401" style="">Cuttack</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="402" style="">Jajpur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="403" style="">Dhenkanal</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="404" style="">Angul</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="405" style="">Nayagarh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="406" style="">Khordha</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="407" style="">Puri</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="408" style="">Ganjam</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="409" style="">Gajapati</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="410" style="">Kandhamal</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="411" style="">Boudh</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="412" style="">Sonepur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="413" style="">Bolangir</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="414" style="">Nuapada</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="415" style="">Kalahandi</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="416" style="">Rayagada</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="417" style="">Nabarangpur</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="418" style="">Koraput</option>
                        <option class="ng-tns-c6-189 ng-star-inserted" value="419" style="">Malkangiri</option>

                    </select>

                    <input class="ng-tns-c6-189" readonly="" role="listbox" type="text" aria-label=" ">

                    Select District

Want to select value form drop-down list like  Deogarh

Body:
usually either of described approached work. Note I'm using async/await in my code

1. Easy way

Declare js click (inject script in console). and then just click any option directly

let jsClick = ($element) => browser.executeScript(
    "arguments[0].click();",
    $element.getWebElement()
);

let $option = $("option[value='395']");

await jsClick($option);

This injected click works differently then protractor .click(). It may click elements even if they are mot visible. Works, but not really UI verification

2. What user would do

Requires scrolling

let scroll = ($element, offsetY = 0) => browser.executeScript(
        `arguments[0].scrollIntoView();
        window.scroll(
            0,window.scrollY-50-(${offsetY})
        );`,
        $element.getWebElement()
     );

await $visibleDropdown.click();
await scroll($yourOption);
await $yourOption.click();

Let me know if neither helped


问:
Cucumber Test execution for gradle project via command line using tags for cucumber feature files
I am looking to execute a cucumber test for a gradle project via command line using specific feature tags.

The command I am using: gradle test -DCucumber.options="-tags @tagname".
Command does execute the tags mentioned.
I have tried using gradle test -DCucumber.options="-tags @tagname" and also gradle test. I didn't find any difference in both the command.

gradle test -DCucumber.options="-tags @tagname" executes the Runtest.java  and tags mentioned in this file, irrespective of what feature tags I pass via command line for example: tagname.

Runtest.java

```<code>@RunWith(Cucumber.class)
@CucumberOptions(features = "src\\test\\resources\\featurefiles", monochrome = true, plugin = {
        "com.eis.listeners.ExtentCucumberFormatter:" }, glue = {
                "com.adminconsole.stepdefs" },tags= {"@adminconsolelogin,@devicemanager,@certificatemanagement"} ,format = { "json:JsonReports/AdminConsole.json" })
</code>```

So here I have mentioned three tags in the Runtest.java.
Now, instead of running all the tags, I wanna run a specific tag via command line.
Command: gradle test -DCucumber.options="-tags @adminconsolelogin", but -DCucumber.options="-tags @adminconsolelogin" part ain't working.

I am looking for a solution where we can run specific tags irrespective of what tag is mentioned in Runtest.java. More precisely pass tags dynamically via command line.

But -DCucumber.options="-tags @tagname" ain't working via command line.
Would appreciate if anyone can provide me with a correct command or strategy or code on how to do it. If the below command is wrong: gradle test -DCucumber.options="-tags @tagname" please correct me.

答:
Update: For Cucumber 6 you need to provide the following statement:

```<code>test {
systemProperty "cucumber.filter.tags", System.getProperty("cucumber.filter.tags")

}
</code>```

You have to bridge the system properties between the gradle JVM and the forked JVM for the tests for this to work.  From issue #1346:

```<code>test {
    systemProperty "cucumber.options", System.getProperty("cucumber.options")
}
</code>```

Add that to your build.gradle and then you can do it on the command-line:

gradle test -Dcucumber.options="-tags @tagname"

Body:
I am looking to execute a cucumber test for a gradle project via command line using specific feature tags.

The command I am using: gradle test -DCucumber.options="-tags @tagname".
Command does execute the tags mentioned.
I have tried using gradle test -DCucumber.options="-tags @tagname" and also gradle test. I didn't find any difference in both the command.

gradle test -DCucumber.options="-tags @tagname" executes the Runtest.java  and tags mentioned in this file, irrespective of what feature tags I pass via command line for example: tagname.

Runtest.java

@RunWith(Cucumber.class)
@CucumberOptions(features = "src\\test\\resources\\featurefiles", monochrome = true, plugin = {
        "com.eis.listeners.ExtentCucumberFormatter:" }, glue = {
                "com.adminconsole.stepdefs" },tags= {"@adminconsolelogin,@devicemanager,@certificatemanagement"} ,format = { "json:JsonReports/AdminConsole.json" })

So here I have mentioned three tags in the Runtest.java.
Now, instead of running all the tags, I wanna run a specific tag via command line.
Command: gradle test -DCucumber.options="-tags @adminconsolelogin", but -DCucumber.options="-tags @adminconsolelogin" part ain't working.

I am looking for a solution where we can run specific tags irrespective of what tag is mentioned in Runtest.java. More precisely pass tags dynamically via command line.

But -DCucumber.options="-tags @tagname" ain't working via command line.
Would appreciate if anyone can provide me with a correct command or strategy or code on how to do it. If the below command is wrong: gradle test -DCucumber.options="-tags @tagname" please correct me.

Body:
Update: For Cucumber 6 you need to provide the following statement:

test {
systemProperty "cucumber.filter.tags", System.getProperty("cucumber.filter.tags")

}

You have to bridge the system properties between the gradle JVM and the forked JVM for the tests for this to work.  From issue #1346:

test {
    systemProperty "cucumber.options", System.getProperty("cucumber.options")
}

Add that to your build.gradle and then you can do it on the command-line:

gradle test -Dcucumber.options="-tags @tagname"


问:
How to build and manipulate the color of 4 squares?
I am asked to build an HTML and CSS page which contains 4 different colored squares that have a double size of each other(For ex. First one 2x2 px, second one 4x4, third one 8x8 and fourth one 16x16), and when the cursor is hovered on the square, the corresponding square receives the color of the square next to it.</p>

答:
Here is short snippet for you. It shows the main concept, then you can tune it somehow to achieve exactly what you need.

const INIT_SIZE = [20,20];
const COLORS = ['red','green','blue','yellow'];

const squares = COLORS.map((color, index) => {
  const el = document.createElement('div');
  el.style.width = INIT_SIZE[0] * Math.pow(2, index) + 'px';
  el.style.height = INIT_SIZE[1] * Math.pow(2, index) + 'px';
  el.style.backgroundColor = color;
  document.body.appendChild(el);
  return el;
});

squares.forEach((sq) => {
  sq.addEventListener('mouseover', (ev) => {
    const tgt = ev.target;
    const curr = squares.indexOf(tgt);
    const newIndex = (curr + 1) == squares.length ? 0 : (curr + 1);
    tgt.style.backgroundColor = squares[newIndex].style.backgroundColor;
  })
})```


问:
SQL Update using subquery
I'm trying to update a table using a sub query but it's not recognising the table alias, when I try and run it a box pops up with 't1.rDate', my query is:

```<code> UPDATE Results SET odds4 =
(SELECT SUM(IIF(odds >= 4, 1, 0)) FROM Results t1
GROUP BY t1.rDate, t1.rTime, t1.rTrack)
WHERE rDate = t1.rDate AND rTime = t1.rTime AND rTrack = t1.rTrack AND t1.rDate
>= #2019/05/28#;
</code>```

Example:

```<code>   rDate   | rTime | rTrack | horse   | odds | odds4
------------------------------------------------------
28/05/2019 | 13:00 | Ascot  | horse1  | 2.5  |  3
28/05/2019 | 13:00 | Ascot  | horse2  | 34   |  3
28/05/2019 | 13:00 | Ascot  | horse3  | 1.4  |  3
28/05/2019 | 13:00 | Ascot  | horse4  | 6    |  3
28/05/2019 | 13:00 | Ascot  | horse5  | 4    |  3
28/05/2019 | 14:30 | Epsom  | horse1  | 3    |  2
28/05/2019 | 14:30 | Epsom  | horse2  | 1.75 |  2
28/05/2019 | 14:30 | Epsom  | horse3  | 2    |  2
28/05/2019 | 14:30 | Epsom  | horse4  | 12   |  2
28/05/2019 | 14:30 | Epsom  | horse5  | 66   |  2
</code>```

答:
Try this:

```<code>UPDATE Results SET odds4 =
                 CASE
                    WHEN odds >= 4 THEN 1
                    ELSE 0
                 END
WHERE rDate >= #2019/05/28#;
</code>```

EDITED CODE :

```<code>UPDATE Results SET odds4 = (SELECT t1.odds4
 FROM
    (
     SELECT  rDate,
                     rTime,
                     rTrack,
                    SUM(IIF(odds >= 4, 1, 0)) AS odds4
      FROM Results
     GROUP BY rDate, rTime, rTrack
    ) AS t1

  WHERE Results.rDate = t1.rDate
    AND Results.rTime = t1.rTime
    AND Results.rTrack = t1.rTrack
)
    WHERE Results.rDate >= #2019/05/28#;
</code>```

Title: SQL Update using subquery

Body:
I'm trying to update a table using a sub query but it's not recognising the table alias, when I try and run it a box pops up with 't1.rDate', my query is:

 UPDATE Results SET odds4 =
(SELECT SUM(IIF(odds >= 4, 1, 0)) FROM Results t1
GROUP BY t1.rDate, t1.rTime, t1.rTrack)
WHERE rDate = t1.rDate AND rTime = t1.rTime AND rTrack = t1.rTrack AND t1.rDate
>= #2019/05/28#;

Example:

   rDate   | rTime | rTrack | horse   | odds | odds4
------------------------------------------------------
28/05/2019 | 13:00 | Ascot  | horse1  | 2.5  |  3
28/05/2019 | 13:00 | Ascot  | horse2  | 34   |  3
28/05/2019 | 13:00 | Ascot  | horse3  | 1.4  |  3
28/05/2019 | 13:00 | Ascot  | horse4  | 6    |  3
28/05/2019 | 13:00 | Ascot  | horse5  | 4    |  3
28/05/2019 | 14:30 | Epsom  | horse1  | 3    |  2
28/05/2019 | 14:30 | Epsom  | horse2  | 1.75 |  2
28/05/2019 | 14:30 | Epsom  | horse3  | 2    |  2
28/05/2019 | 14:30 | Epsom  | horse4  | 12   |  2
28/05/2019 | 14:30 | Epsom  | horse5  | 66   |  2

Body:
Try this:

UPDATE Results SET odds4 =
                 CASE
                    WHEN odds >= 4 THEN 1
                    ELSE 0
                 END
WHERE rDate >= #2019/05/28#;

EDITED CODE :

UPDATE Results SET odds4 = (SELECT t1.odds4
 FROM
    (
     SELECT  rDate,
                     rTime,
                     rTrack,
                    SUM(IIF(odds >= 4, 1, 0)) AS odds4
      FROM Results
     GROUP BY rDate, rTime, rTrack
    ) AS t1

  WHERE Results.rDate = t1.rDate
    AND Results.rTime = t1.rTime
    AND Results.rTrack = t1.rTrack
)
    WHERE Results.rDate >= #2019/05/28#;